//
//  Home.m
//  A One POS
//
//  Created by AonePOS on 24/09/13.
//  Copyright (c) 2013 AonePOS. All rights reserved.
//

#import "Home.h"
#import "general data.h"
#import "ePOS-Print.h"
#import "ShowMess.h"
#import <StarIO/SMPort.h>
#import "PrinterFunctions.h"
#import "CommonEnum.h"
#import "Toast+UIView.h"
#import "Settings.h"
#import "Profile.h"
#import "Stores.h"
#import "Inventory.h"
#import "Customers.h"
#import "Employees.h"
#import "Reports.h"
#import "Contacts.h"
#import "DataBaseManager.h"
#import "SwipeViewController.h"
#import "ServersyncClass.h"
#import "general data.h"
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
@interface Home ()
{
    
}

@end

@implementation Home
{
    UIAlertView *mercury;
    Settings *settingsview;
    ServersyncClass *serverSyncClassObject;
    general_data *generalDataObject;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    
    generalDataObject =[general_data new];
    [generalDataObject  GetuserDataVariablesMethod];
    serverSyncClassObject=[ServersyncClass new];
    [NSThread detachNewThreadSelector:@selector(ServerSyncronizationMethod) toTarget:serverSyncClassObject withObject:nil];
    StoreID=HoldStatus=EmployeeID=paymentType=InVoiceCustomer=@"";InvoiceCheckNo=@"";
    
  
    [super viewDidLoad];
    
    isLandScope = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
   // [NSThread detachNewThreadSelector:@selector(ServerSyncronizationMethod) toTarget:[ServersyncClass sharedInstance] withObject:nil];

    y=0;
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
    {
        y=y+20;
        
        
    }
    CGFloat width,height;
    width=self.view.frame.size.width;
    height=self.view.frame.size.height;
    // //NSLog(@" %f,%f",width,height);
    
    backgroundcolorview=[[UIView alloc]init];
    backgroundcolorview.frame=CGRectMake(0,y,width,height-100);
    //[backgroundcolorview  setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]]];
    
    [backgroundcolorview  setBackgroundColor:[UIColor colorWithPatternImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"background" ofType:@"jpg"]]]];
    
    [self.view addSubview:backgroundcolorview];
    
    // [ContactsBtn setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"contactsactive" ofType:@"png"]] forState:UIControlStateNormal];
    
    sidemenu=[[UIView alloc]init];
    sidemenu.frame=CGRectMake(0, 1,170 ,height-150);
    //sidemenu.hidden=YES;
    //[sidemenu  setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bluecolorstrip.jpg"]]];
    [sidemenu  setBackgroundColor:[UIColor colorWithPatternImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bluecolorstrip" ofType:@"jpg"]]]];
    
    NSString *pagetitle;
    pagetitle=@"POS";
    navBar = [[UINavigationBar alloc] init];
    navBar.frame=CGRectMake(0, 0,width, 50.0);
    
    // [logobackview setImage:[UIImage imageNamed:@"logo-login-bg.png"]];
    //[navBar setBackgroundImage:[UIImage imageNamed:@"logo-login-bg-short.png"] forBarMetrics:UIBarMetricsDefault];
    [navBar setBackgroundImage:[UIImage imageNamed:@"logo-login-bg-short.png"] forBarMetrics:UIBarMetricsDefault];
    
    //[navBar setBackgroundColor:[UIColor blackColor]];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
    titleLabel.font=[UIFont boldSystemFontOfSize:30.0];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.text =pagetitle;
    [self.navigationItem setTitleView:titleLabel];
    titleLabel=nil;
    
    //navItem.title = pagetitle;
    [navBar pushNavigationItem:self.navigationItem animated:false];
    [backgroundcolorview addSubview:navBar];
    
    
    menubutton = [UIButton buttonWithType:UIButtonTypeCustom];
    [menubutton setFrame:CGRectMake(0,0,50,50)];
    [menubutton addTarget:self action:@selector(menuclicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[menubutton setImage:[UIImage imageNamed:@"arrow.png"] forState:UIControlStateNormal];
    [menubutton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"arrow" ofType:@"png"]] forState:UIControlStateNormal];
    [navBar addSubview:menubutton];
    
    
    logoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [logoBtn setFrame:CGRectMake(60,0,250,50)];
    // [logoBtn addTarget:self action:@selector(menuclicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[logoBtn setImage:[UIImage imageNamed:@"headeraonelogo.png"] forState:UIControlStateNormal];
    [logoBtn setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"headeraonelogo" ofType:@"png"]] forState:UIControlStateNormal];
    [navBar addSubview:logoBtn];
    sationLbl=[[UILabel alloc] init];
    
    sationLbl.frame=CGRectMake(navBar.frame.size.width-280, 5,100, 40);
    
    [sationLbl setFont:[UIFont systemFontOfSize:13.0f]];
    [sationLbl setBackgroundColor:[UIColor clearColor]];
    [sationLbl setTextColor:[UIColor blackColor]];
    [sationLbl setText:@"Station No:1"];
    sationLbl.lineBreakMode = NSLineBreakByWordWrapping;
    sationLbl.numberOfLines = 2;
    [sationLbl setTextAlignment:NSTextAlignmentLeft];
    [navBar addSubview:sationLbl];
    
    
    EmpIdlbl=[[UILabel alloc] init];
    EmpIdlbl.frame=CGRectMake(navBar.frame.size.width-193, 5,150, 40);
    
    [EmpIdlbl setFont:[UIFont systemFontOfSize:13.0f]];
    [EmpIdlbl setBackgroundColor:[UIColor clearColor]];
    [EmpIdlbl setTextColor:[UIColor blackColor]];
    [EmpIdlbl setText:[NSString stringWithFormat:@"Employee Id: %@",[generalDataObject  userID]]];
    EmpIdlbl.lineBreakMode = NSLineBreakByWordWrapping;
    // EmpIdlbl.numberOfLines = 2;
    [EmpIdlbl setTextAlignment:NSTextAlignmentLeft];
    [navBar addSubview:EmpIdlbl];
    
    
    Timelbl=[[UILabel alloc] init];
    
    Timelbl.frame=CGRectMake(navBar.frame.size.width-62, 6,80, 40);
    
    [Timelbl setFont:[UIFont systemFontOfSize:13.0f]];
    [Timelbl setBackgroundColor:[UIColor clearColor]];
    [Timelbl setTextColor:[UIColor blackColor]];
    NSDate *aDate = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterShortStyle];
    [formatter setTimeStyle:NSDateFormatterNoStyle];
    [formatter setDateFormat:@"HH:mm:ss"];
    NSString *datestr;
    datestr=[formatter stringFromDate:aDate];
    Timelbl.text=datestr;
    //Timelbl.text=[NSString stringWithFormat:@"%@:%@",@"Time",datestr];
    
    // timer is set & will be triggered each second
    //[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(showTime) userInfo:nil repeats:YES];
    Timelbl.lineBreakMode = NSLineBreakByWordWrapping;
    Timelbl.numberOfLines = 2;
    [Timelbl setTextAlignment:NSTextAlignmentLeft];
    [navBar addSubview:Timelbl];
    
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
    [menubutton addGestureRecognizer:longPress];
    
    p=1;
    @autoreleasepool {
  
    for (int i=0; i< 10; i++)
    {
        
        categorybutton = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [categorybutton setFrame:CGRectMake(0,p,170,40)];
        [categorybutton addTarget:self action:@selector(categotybuttonclicked:) forControlEvents:UIControlEventTouchUpInside];
        categorybutton.tag=i;
        if (categorybutton.tag == 0){
            //[categorybutton setImage:[UIImage imageNamed:@"posactive.png"] forState:UIControlStateNormal];
            [categorybutton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"posactive" ofType:@"png"]] forState:UIControlStateNormal];
        }else if (categorybutton.tag == 1){
            //[categorybutton setImage:[UIImage imageNamed:@"profilenormal2.png"] forState:UIControlStateNormal];
            
            [categorybutton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"profilenormal2" ofType:@"png"]] forState:UIControlStateNormal];
        }else if (categorybutton.tag == 2){
            // [categorybutton setImage:[UIImage imageNamed:@"inventorynormal2.png"] forState:UIControlStateNormal];
            
            [categorybutton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"inventorynormal2" ofType:@"png"]] forState:UIControlStateNormal];
            
        }else if(categorybutton.tag == 3){
            //[categorybutton setImage:[UIImage imageNamed:@"customernormal2.png"] forState:UIControlStateNormal];
            [categorybutton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"customernormal2" ofType:@"png"]] forState:UIControlStateNormal];
        }else if (categorybutton.tag == 4){
            //[categorybutton setImage:[UIImage imageNamed:@"employeenormal2.png"] forState:UIControlStateNormal];
            [categorybutton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"employeenormal2" ofType:@"png"]] forState:UIControlStateNormal];
        }else if(categorybutton.tag == 5){
            //[categorybutton setImage:[UIImage imageNamed:@"settingsnormal2.png"] forState:UIControlStateNormal];
            
            [categorybutton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"settingsnormal2" ofType:@"png"]] forState:UIControlStateNormal];
        }else if(categorybutton.tag == 6){
            //[categorybutton setImage:[UIImage imageNamed:@"reportsnormal2.png"] forState:UIControlStateNormal];
            
            [categorybutton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"reportsnormal2" ofType:@"png"]] forState:UIControlStateNormal];
        }else if(categorybutton.tag == 7){
            //[categorybutton setImage:[UIImage imageNamed:@"contactsnormal2.png"] forState:UIControlStateNormal];
            [categorybutton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"contactsnormal2" ofType:@"png"]] forState:UIControlStateNormal];
            
        }else if (categorybutton.tag == 8){
            //[categorybutton setImage:[UIImage imageNamed:@"storesnormal.png"] forState:UIControlStateNormal];
            [categorybutton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"storesnormal" ofType:@"png"]] forState:UIControlStateNormal];
        }else if (categorybutton.tag == 9){
            //[categorybutton setImage:[UIImage imageNamed:@"bluecolorstrip.jpg"] forState:UIControlStateNormal];
        }
        [sidemenu addSubview:categorybutton];
        p=p+categorybutton.frame.size.height;
    }
    }
    // //NSLog(@"p value is %d",p);s
    
    Modelbl=[[UILabel alloc] init];
    Modelbl.frame=CGRectMake(20,400,60, 30);
    [Modelbl setFont:[UIFont systemFontOfSize:20.0f]];
    [Modelbl setBackgroundColor:[UIColor clearColor]];
    [Modelbl setTextColor:[UIColor whiteColor]];
    
    [Modelbl setText:@"Mode"];
    [Modelbl setTextAlignment:NSTextAlignmentLeft];
    [sidemenu addSubview:Modelbl];
    
    Myswitch=[[UISwitch alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    Myswitch.frame=CGRectMake(Modelbl.frame.size.width+20,400,100,40);
    
    [Myswitch addTarget:self action:@selector(MyswitchClicked:) forControlEvents:UIControlEventValueChanged];
    [Myswitch setOn:TRUE animated:YES];
    
    [sidemenu addSubview:Myswitch];
    
    
    mainview=[[UIView alloc]init];
    mainview.frame=CGRectMake(10,50,width-20,height-160);
    [mainview setBackgroundColor:[UIColor grayColor]];
    [mainview  setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"hqbackground69opacity.png"]]];
    [backgroundcolorview addSubview:mainview];
    
    
    logoimageview=[[UIImageView alloc]init];
    logoimageview.frame=CGRectMake(50, (backgroundcolorview.frame.size.height)+5+y,(height-(backgroundcolorview.frame.size.height)-30), (height-(backgroundcolorview.frame.size.height)-30));
    [logoimageview setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aoneposlogo" ofType:@"png"]]];
    [self.view addSubview:logoimageview];
    
    helpiconButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [helpiconButton setFrame:CGRectMake(width-180,y+40,70,70)];
    [helpiconButton addTarget:self action:@selector(helpiconclicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[helpiconButton setImage:[UIImage imageNamed:@"helpicon.png"] forState:UIControlStateNormal];
    
    [helpiconButton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"helpicon" ofType:@"png"]] forState:UIControlStateNormal];
    
    [self.view addSubview:helpiconButton];
    
    logouticonButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [logouticonButton setFrame:CGRectMake(width-100,y+40,70,70)];
    [logouticonButton addTarget:self action:@selector(logoutButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[logouticonButton setImage:[UIImage imageNamed:@"logoutbutton.png"] forState:UIControlStateNormal];
    [logouticonButton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"logoutbutton" ofType:@"png"]] forState:UIControlStateNormal];
    
    [self.view addSubview:logouticonButton];
    
    //[self.view addSubview:logouticonButton];
//Home view
    
    
    HomebackView=[[UIView alloc]initWithFrame:CGRectMake(0, 5,mainview.frame.size.width, mainview.frame.size.height-10)];
    
    [HomebackView setBackgroundColor:[UIColor colorWithRed:60.0f/255.0f green:101.0f/255.0f blue:134.0f/255.0f alpha:1.0f]];
    CGFloat homewidth=(HomebackView.frame.size.width/2);
    CGFloat btnw=homewidth/2;
    [mainview addSubview:HomebackView];
    
    ProductscanBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    [ProductscanBtn setTitle:@"Enter Barcode" forState:UIControlStateNormal];
    //[ProductscanBtn setBackgroundImage:[UIImage imageNamed:@"productscanbutton.png"] forState:UIControlStateNormal];
    
    [ProductscanBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"productscanbutton" ofType:@"png"]] forState:UIControlStateNormal];
    ProductscanBtn.frame=CGRectMake(0,5,btnw,40);
    
   // [ProductscanBtn addTarget:self action:@selector(ProdutScanClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [ProductscanBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    //[HomebackView addSubview:ProductscanBtn];
    
    ProductscanField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    ProductscanField.frame=CGRectMake(0,5,btnw,40);
    ProductscanField.delegate=self;
    ProductscanField.placeholder = @"Enter Barcode";
    UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    [ProductscanField setValue:[UIColor colorWithRed:120.0/255.0 green:116.0/255.0 blue:115.0/255.0 alpha:1.0] forKeyPath:@"_placeholderLabel.textColor"];
    
    //[UIColor colorWithRed:120.0/255.0 green:116.0/255.0 blue:115.0/255.0 alpha:1.0]
    ProductscanField.leftView = paddingview;
    ProductscanField.textAlignment= NSTextAlignmentLeft;
    ProductscanField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    ProductscanField.leftViewMode = UITextFieldViewModeAlways;
    //[ProductscanField setBackground:[UIImage imageNamed:@"productscanbutton.png"]];
    [ProductscanField setBackground:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"productscanbutton" ofType:@"png"]]];
    
    
    [ProductscanField setAutocorrectionType:UITextAutocorrectionTypeNo];
    
    //[ProductscanField addTarget:self action:@selector(productScanDidend) forControlEvents:UIControlEventEditingDidEnd];
    
    [HomebackView addSubview:ProductscanField];
    
    Quantitybtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    [Quantitybtn setTitle:@"Quantity" forState:UIControlStateNormal];
    // [Quantitybtn setBackgroundImage:[UIImage imageNamed:@"litebutton.png"] forState:UIControlStateNormal];
    [Quantitybtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"litebutton" ofType:@"png"]] forState:UIControlStateNormal];
    
    Quantitybtn.frame=CGRectMake(ProductscanBtn.frame.size.width+10,5,btnw-100, 40);
    [Quantitybtn addTarget:self action:@selector(QuantitybtnClikced) forControlEvents:UIControlEventTouchUpInside];
    
    [Quantitybtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    //[HomebackView addSubview:Quantitybtn];
    
    QantyField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    if (isLandScope){
        QantyField.frame=CGRectMake(ProductscanBtn.frame.size.width+5,5,btnw-180,40);
    }else{
        QantyField.frame=CGRectMake(ProductscanBtn.frame.size.width+5,5,btnw-140,40);
    }
    
    QantyField.delegate=self;
    
    UIView *paddingview2=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    QantyField.placeholder = @"Qty";
    QantyField.leftView = paddingview2;
    [QantyField setValue:[UIColor colorWithRed:120.0/255.0 green:116.0/255.0 blue:115.0/255.0 alpha:1.0] forKeyPath:@"_placeholderLabel.textColor"];
    QantyField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    QantyField.leftViewMode = UITextFieldViewModeAlways;
    QantyField.keyboardType=UIKeyboardTypeNumberPad;
    QantyField.keyboardType=UIKeyboardTypeNumberPad;
    // [QantyField setBackground:[UIImage imageNamed:@"productscanbutton.png"]];
    [QantyField setBackground:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"productscanbutton" ofType:@"png"]]];
    [QantyField setAutocorrectionType:UITextAutocorrectionTypeNo];
    [HomebackView addSubview:QantyField];
    
    QtyGobtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [QtyGobtn setTitle:@"Go" forState:UIControlStateNormal];
    //[QtyGobtn setBackgroundImage:[UIImage imageNamed:@"gobuttonpos.png"] forState:UIControlStateNormal];
    [QtyGobtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"gobuttonpos" ofType:@"png"]] forState:UIControlStateNormal];
     QtyGobtn.frame=CGRectMake(ProductscanBtn.frame.size.width+QantyField.frame.size.width+12,5,40, 40);
    [QtyGobtn addTarget:self action:@selector(QuantitybtnClikced) forControlEvents:UIControlEventTouchUpInside];
    [QtyGobtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:QtyGobtn];
    
    SearchBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [SearchBtn setTitle:@"Search" forState:UIControlStateNormal];
    // [SearchBtn setBackgroundImage:[UIImage imageNamed:@"searchbuttonpos.png"] forState:UIControlStateNormal];
    [SearchBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"searchbuttonpos" ofType:@"png"]] forState:UIControlStateNormal];
    
    if (isLandScope){
        SearchBtn.frame=CGRectMake(ProductscanBtn.frame.size.width+20+QantyField.frame.size.width+40,5,btnw-130, 40);
    }else{
        SearchBtn.frame=CGRectMake(ProductscanBtn.frame.size.width+20+QantyField.frame.size.width+40,5,btnw-110, 40);
    }
    [SearchBtn addTarget:self action:@selector(SearchBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [SearchBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:SearchBtn];
    
    tablestripview=[[UIView alloc]initWithFrame:CGRectMake(0, 60,homewidth,30)];
    [tablestripview setBackgroundColor:[UIColor colorWithRed:229.0f/255.0f green:229.0f/255.0f blue:229.0f/255.0f alpha:1.0f]];
    //CGFloat homewidth=(tablestripview.frame.size.width/2);
    CGFloat sw=tablestripview.frame.size.width/5;
    [HomebackView addSubview:tablestripview];
    
    snolbl=[[UILabel alloc] init];
    snolbl.frame=CGRectMake(0,0, sw-30, 30);
    [snolbl setFont:[UIFont systemFontOfSize:18.0f]];
    [snolbl setBackgroundColor:[UIColor clearColor]];
    [snolbl setTextColor:[UIColor colorWithRed:37.0f/255.0f green:80.0f/255.0f blue:114.0f/255.0f alpha:1.0f]];
    [snolbl setText:@"S.No"];
    [snolbl setTextAlignment:NSTextAlignmentLeft];
    [tablestripview addSubview:snolbl];
    
    itemlbl=[[UILabel alloc] init];
    itemlbl.frame=CGRectMake(snolbl.frame.size.width,0, sw+50, 30);
    [itemlbl setFont:[UIFont systemFontOfSize:18.0f]];
    [itemlbl setBackgroundColor:[UIColor clearColor]];
    [itemlbl setTextColor:[UIColor colorWithRed:37.0f/255.0f green:80.0f/255.0f blue:114.0f/255.0f alpha:1.0f]];
    [itemlbl setText:@"Item #"];
    [itemlbl setTextAlignment:NSTextAlignmentLeft];
    [tablestripview addSubview:itemlbl];
    
    iteminfolbl=[[UILabel alloc] init];
    iteminfolbl.frame=CGRectMake(snolbl.frame.size.width+itemlbl.frame.size.width,0, sw+60, 30);
    [iteminfolbl setFont:[UIFont systemFontOfSize:18.0f]];
    [iteminfolbl setBackgroundColor:[UIColor clearColor]];
    [iteminfolbl setTextColor:[UIColor colorWithRed:37.0f/255.0f green:80.0f/255.0f blue:114.0f/255.0f alpha:1.0f]];
    
    [iteminfolbl setText:@"Item Info"];
    [iteminfolbl setTextAlignment:NSTextAlignmentLeft];
    [tablestripview addSubview:iteminfolbl];
    
    qntylbl=[[UILabel alloc] init];
    qntylbl.frame=CGRectMake(snolbl.frame.size.width+itemlbl.frame.size.width+iteminfolbl.frame.size.width-40,0, sw-10, 30);
    [qntylbl setFont:[UIFont systemFontOfSize:18.0f]];
    [qntylbl setBackgroundColor:[UIColor clearColor]];
    [qntylbl setTextColor:[UIColor colorWithRed:37.0f/255.0f green:80.0f/255.0f blue:114.0f/255.0f alpha:1.0f]];
    
    [qntylbl setText:@"Qty"];
    [qntylbl setTextAlignment:NSTextAlignmentLeft];
    [tablestripview addSubview:qntylbl];
    
    pricelbl=[[UILabel alloc] init];
    pricelbl.frame=CGRectMake(snolbl.frame.size.width+itemlbl.frame.size.width+iteminfolbl.frame.size.width+qntylbl.frame.size.width-70,0, sw-20, 30);
    [pricelbl setFont:[UIFont systemFontOfSize:18.0f]];
    [pricelbl setBackgroundColor:[UIColor clearColor]];
    [pricelbl setTextColor:[UIColor colorWithRed:37.0f/255.0f green:80.0f/255.0f blue:114.0f/255.0f alpha:1.0f]];
    [pricelbl setText:@"Price"];
    [pricelbl setTextAlignment:NSTextAlignmentLeft];
    [tablestripview addSubview:pricelbl];
    
    if (isLandScope){
        ProductslistTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 90,homewidth,330) style:UITableViewStylePlain];
    }else{
        ProductslistTable = [[UITableView alloc] initWithFrame:CGRectMake(0,90,homewidth,560) style:UITableViewStylePlain];
    }
    
    ProductslistTable.backgroundColor=[UIColor whiteColor];
    ProductslistTable.delegate = self;
    ProductslistTable.dataSource = self;
    ProductslistTable.scrollEnabled = YES;
    //printermethodsTable.hidden=YES;
    [ProductslistTable.layer setBorderWidth: 1.0];
    //[titlesdata_table.layer setCornerRadius:8.0f];
    //[titlesdata_table.layer setMasksToBounds:YES];
    [ProductslistTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [HomebackView addSubview:ProductslistTable];
    
    
    CGFloat deW=ProductslistTable.frame.size.width/5;
    
    
    DeleteBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    [DeleteBtn setTitle:@"Delete" forState:UIControlStateNormal];
    //[DeleteBtn setBackgroundImage:[UIImage imageNamed:@"bluebutton.png"] forState:UIControlStateNormal];
    [DeleteBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bluebutton" ofType:@"png"]] forState:UIControlStateNormal];
    
    DeleteBtn.frame=CGRectMake(0,95+ProductslistTable.frame.size.height,deW-20, 40);
    
    [DeleteBtn addTarget:self action:@selector(DeleteAllDataClicked) forControlEvents:UIControlEventTouchUpInside];
    //DeleteBtn.titleLabel.font = [UIFont fontWithName:@"Arial-Bold" size:16.0];
    [DeleteBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:DeleteBtn];
    
    DiscountBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    [DiscountBtn setTitle:@"Discount" forState:UIControlStateNormal];
    //[DiscountBtn setBackgroundImage:[UIImage imageNamed:@"bluebutton.png"] forState:UIControlStateNormal];
    [DiscountBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bluebutton" ofType:@"png"]] forState:UIControlStateNormal];
    DiscountBtn.frame=CGRectMake(DeleteBtn.frame.size.width+5,95+ProductslistTable.frame.size.height,deW-10, 40);
    
    [DiscountBtn addTarget:self action:@selector(ChangeDiscountClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [DiscountBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:DiscountBtn];
    
    QuantyChangeBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    [QuantyChangeBtn setTitle:@"QuantityChange" forState:UIControlStateNormal];
    //[QuantyChangeBtn setBackgroundImage:[UIImage imageNamed:@"bluebutton.png"] forState:UIControlStateNormal];
    [QuantyChangeBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bluebutton" ofType:@"png"]] forState:UIControlStateNormal];
    
    QuantyChangeBtn.frame=CGRectMake(DeleteBtn.frame.size.width+5+DiscountBtn.frame.size.width+10,95+ProductslistTable.frame.size.height,deW+60, 40);
    
    [QuantyChangeBtn addTarget:self action:@selector(ChangequantityClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [QuantyChangeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:QuantyChangeBtn];
    
    PriceChangeBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    [PriceChangeBtn setTitle:@"PriceChange" forState:UIControlStateNormal];
    //[PriceChangeBtn setBackgroundImage:[UIImage imageNamed:@"bluebutton.png"] forState:UIControlStateNormal];
    [PriceChangeBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bluebutton" ofType:@"png"]] forState:UIControlStateNormal];
    PriceChangeBtn.frame=CGRectMake(DeleteBtn.frame.size.width+5+QuantyChangeBtn.frame.size.width+10+DiscountBtn.frame.size.width+10,95+ProductslistTable.frame.size.height,deW+20, 40);
    
    [PriceChangeBtn addTarget:self action:@selector(PriceChangeClciked) forControlEvents:UIControlEventTouchUpInside];
    
    [PriceChangeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:PriceChangeBtn];
    
    custBackview=[[UIView alloc]initWithFrame:CGRectMake(0, 140+ProductslistTable.frame.size.height,homewidth,HomebackView.frame.size.height-(140+ProductslistTable.frame.size.height))];
    
    [custBackview setBackgroundColor:[UIColor whiteColor]];
    //CGFloat homewidth=(tablestripview.frame.size.width/2);
    CGFloat Cw=custBackview.frame.size.width/4;
    CGFloat CH=custBackview.frame.size.height/2;
    [HomebackView addSubview:custBackview];
    
    AddBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    AddBtn.titleLabel.font=[UIFont systemFontOfSize:20.0f];
    [AddBtn setTitle:@"Add" forState:UIControlStateNormal];
    //[AddBtn setBackgroundImage:[UIImage imageNamed:@"greenbutton2.png"] forState:UIControlStateNormal];
    [AddBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"greenbutton2" ofType:@"png"]] forState:UIControlStateNormal];
    AddBtn.frame=CGRectMake(0,140+ProductslistTable.frame.size.height,Cw-20, CH);
    
    [AddBtn addTarget:self action:@selector(AddCustomerClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [AddBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:AddBtn];
    
    FindBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    [FindBtn setTitle:@"Find" forState:UIControlStateNormal];
    //[FindBtn setBackgroundImage:[UIImage imageNamed:@"greenbutton2.png"] forState:UIControlStateNormal]
    [FindBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"greenbutton2" ofType:@"png"]] forState:UIControlStateNormal];
    
    FindBtn.frame=CGRectMake(0,140+ProductslistTable.frame.size.height+CH,Cw-20, CH);
    FindBtn.titleLabel.font=[UIFont systemFontOfSize:20.0f];
    [FindBtn addTarget:self action:@selector(FindCustomerClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [FindBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:FindBtn];
    
    
    CustomerBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    [CustomerBtn setTitle:@"Customer" forState:UIControlStateNormal];
    //[CustomerBtn setBackgroundImage:[UIImage imageNamed:@"litebutton.png"] forState:UIControlStateNormal];
    [CustomerBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"litebutton" ofType:@"png"]] forState:UIControlStateNormal];
    CustomerBtn.frame=CGRectMake(AddBtn.frame.size.width,140+ProductslistTable.frame.size.height+2,Cw, 40);
    
    [CustomerBtn addTarget:self action:@selector(CustomerBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [CustomerBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [HomebackView addSubview:CustomerBtn];
    
    CustomerinflBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    [CustomerinflBtn setTitle:@"Customer Info" forState:UIControlStateNormal];
    //[CustomerinflBtn setBackgroundImage:[UIImage imageNamed:@"litebutton.png"] forState:UIControlStateNormal];
    [CustomerinflBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"litebutton" ofType:@"png"]] forState:UIControlStateNormal];
    
    CustomerinflBtn.frame=CGRectMake(AddBtn.frame.size.width+CustomerBtn.frame.size.width,140+ProductslistTable.frame.size.height+2,Cw+20, 40);
    
    [CustomerinflBtn addTarget:self action:@selector(CustomerInfoClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [CustomerinflBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [HomebackView addSubview:CustomerinflBtn];
    
    
    Customernamelbl=[[UILabel alloc] init];
    Customernamelbl.frame=CGRectMake(FindBtn.frame.size.width,140+ProductslistTable.frame.size.height+2+CustomerBtn.frame.size.height+5,Cw+Cw+100, 30);
    [Customernamelbl setFont:[UIFont systemFontOfSize:18.0f]];
    [Customernamelbl setBackgroundColor:[UIColor clearColor]];
    [Customernamelbl setTextColor:[UIColor blackColor]];
    
    [Customernamelbl setTextAlignment:NSTextAlignmentLeft];
    [HomebackView addSubview:Customernamelbl];
    
    CustomerNolbl=[[UILabel alloc] init];
    CustomerNolbl.frame=CGRectMake(FindBtn.frame.size.width,140+ProductslistTable.frame.size.height+2+CustomerBtn.frame.size.height+Customernamelbl.frame.size.height+10,Cw+Cw+100, 30);
    [CustomerNolbl setFont:[UIFont systemFontOfSize:18.0f]];
    [CustomerNolbl setBackgroundColor:[UIColor clearColor]];
    [CustomerNolbl setTextColor:[UIColor blackColor]];
    
    [CustomerNolbl setTextAlignment:NSTextAlignmentLeft];
    [HomebackView addSubview:CustomerNolbl];
    
    
    SubtotalView=[[UIView alloc]initWithFrame:CGRectMake(homewidth+10,0,homewidth-10,100)];
    
    //[SubtotalView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"postaxbg.png"
    
    
    [SubtotalView setBackgroundColor:[UIColor colorWithPatternImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"postaxbg" ofType:@"png"]] ]];
    
    
    //CGFloat homewidth=(tablestripview.frame.size.width/2);
    CGFloat subW=SubtotalView.frame.size.width/2;
    
    [HomebackView addSubview:SubtotalView];
    
    Subtlbl=[[UILabel alloc] init];
    Subtlbl.frame=CGRectMake(5,5,subW,30);
    [Subtlbl setFont:[UIFont systemFontOfSize:20.0f]];
    [Subtlbl setBackgroundColor:[UIColor clearColor]];
    [Subtlbl setTextColor:[UIColor blackColor]];
    [Subtlbl setText:@"Sub Total"];
    [Subtlbl setTextAlignment:NSTextAlignmentLeft];
    [SubtotalView addSubview:Subtlbl];
    
    SubTDisplaylbl=[[UILabel alloc] init];
    SubTDisplaylbl.frame=CGRectMake(subW+80,0,subW,30);
    [SubTDisplaylbl setFont:[UIFont systemFontOfSize:20.0f]];
    [SubTDisplaylbl setBackgroundColor:[UIColor clearColor]];
    [SubTDisplaylbl setTextColor:[UIColor blackColor]];
    [SubTDisplaylbl setText:@"$ 0.00"];
    [SubTDisplaylbl setTextAlignment:NSTextAlignmentLeft];
    [SubtotalView addSubview:SubTDisplaylbl];
    
    Taxlbl=[[UILabel alloc] init];
    Taxlbl.frame=CGRectMake(5,60,subW,30);
    [Taxlbl setFont:[UIFont systemFontOfSize:20.0f]];
    [Taxlbl setBackgroundColor:[UIColor clearColor]];
    [Taxlbl setTextColor:[UIColor blackColor]];
    [Taxlbl setText:@"Tax"];
    [Taxlbl setTextAlignment:NSTextAlignmentLeft];
    [SubtotalView addSubview:Taxlbl];
    
    taxDlbl=[[UILabel alloc] init];
    taxDlbl.frame=CGRectMake(subW+80,60,subW,30);
    [taxDlbl setFont:[UIFont systemFontOfSize:20.0f]];
    [taxDlbl setBackgroundColor:[UIColor clearColor]];
    [taxDlbl setTextColor:[UIColor blackColor]];
    [taxDlbl setText:@"$ 0.00"];
    [taxDlbl setTextAlignment:NSTextAlignmentLeft];
    [SubtotalView addSubview:taxDlbl];
    
    
    
    blackstripview=[[UIView alloc]initWithFrame:CGRectMake(homewidth+10,SubtotalView.frame.size.height,homewidth-10,2)];
    
    [blackstripview setBackgroundColor:[UIColor blackColor]];
    //CGFloat homewidth=(tablestripview.frame.size.width/2);
    [HomebackView addSubview:blackstripview];
    GrandtotalView=[[UIView alloc]initWithFrame:CGRectMake(homewidth+10,SubtotalView.frame.size.height+2,homewidth-10,40)];
    
    //[GrandtotalView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"grandtotal.png"]]];
    
    [GrandtotalView setBackgroundColor:[UIColor colorWithPatternImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"grandtotal" ofType:@"png"]]]];
    
    
    CGFloat GW=GrandtotalView.frame.size.width/2;
    //CGFloat homewidth=(tablestripview.frame.size.width/2);
    [HomebackView addSubview:GrandtotalView];
    
    GrandTlbl=[[UILabel alloc] init];
    GrandTlbl.frame=CGRectMake(5,5,GW,30);
    [GrandTlbl setFont:[UIFont systemFontOfSize:25.0f]];
    [GrandTlbl setBackgroundColor:[UIColor clearColor]];
    [GrandTlbl setTextColor:[UIColor whiteColor]];
    [GrandTlbl setText:@"Grand Total"];
    [GrandTlbl setTextAlignment:NSTextAlignmentLeft];
    [GrandtotalView addSubview:GrandTlbl];
    
    GTotalDlbl=[[UILabel alloc] init];
    GTotalDlbl.frame=CGRectMake(subW+80,5,GW,30);
    [GTotalDlbl setFont:[UIFont systemFontOfSize:20.0f]];
    [GTotalDlbl setBackgroundColor:[UIColor clearColor]];
    [GTotalDlbl setTextColor:[UIColor whiteColor]];
    [GTotalDlbl setText:@"$ 0.00"];
    [GTotalDlbl setTextAlignment:NSTextAlignmentLeft];
    [GrandtotalView addSubview:GTotalDlbl];
    
    CGFloat Vwidth=homewidth/2;
    PayBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [PayBtn setTitle:@"Pay" forState:UIControlStateNormal];
    //[PayBtn setBackgroundImage:[UIImage imageNamed:@"paybuttonpos.png"] forState:UIControlStateNormal];
    [PayBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"paybuttonpos" ofType:@"png"]] forState:UIControlStateNormal];
    PayBtn.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height+45,Vwidth-10, 50);
    PayBtn.titleLabel.font = [UIFont systemFontOfSize:22.0f];
    [PayBtn addTarget:self action:@selector(PayBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [PayBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:PayBtn];
    
    
    retraiveOnHoldBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
    // [retraiveOnHoldBtn setBackgroundImage:[UIImage imageNamed:@"paybuttonpos.png"] forState:UIControlStateNormal];
    [retraiveOnHoldBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"paybuttonpos" ofType:@"png"]] forState:UIControlStateNormal];
    
    retraiveOnHoldBtn.titleLabel.font = [UIFont systemFontOfSize:22.0f];
    retraiveOnHoldBtn.frame=CGRectMake(homewidth+10+PayBtn.frame.size.width+10,SubtotalView.frame.size.height+45,Vwidth-10, 50);
    
    [retraiveOnHoldBtn addTarget:self action:@selector(FetchOnHoldClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [retraiveOnHoldBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:retraiveOnHoldBtn];
    
    PrintLastInvcBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [PrintLastInvcBtn setTitle:@"Print LastInvoice" forState:UIControlStateNormal];
    //[PrintLastInvcBtn setBackgroundImage:[UIImage imageNamed:@"paybuttonpos.png"] forState:UIControlStateNormal];
    [PrintLastInvcBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"paybuttonpos" ofType:@"png"]] forState:UIControlStateNormal];
    PrintLastInvcBtn.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height+100,Vwidth-10, 40);
    
    [PrintLastInvcBtn addTarget:self action:@selector(PrintlastVoiceClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [PrintLastInvcBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:PrintLastInvcBtn];
    
    
    
    RecallBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [RecallBtn setTitle:@"Recall Invoice" forState:UIControlStateNormal];
    //[RecallBtn setBackgroundImage:[UIImage imageNamed:@"paybuttonpos.png"] forState:UIControlStateNormal];
    [RecallBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"paybuttonpos" ofType:@"png"]] forState:UIControlStateNormal];
    RecallBtn.frame=CGRectMake(homewidth+20+PrintLastInvcBtn.frame.size.width,SubtotalView.frame.size.height+100,Vwidth-10, 40);
    
    [RecallBtn addTarget:self action:@selector(RecallInVoiceClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [RecallBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:RecallBtn];
    
    VoidInVoiceBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [VoidInVoiceBtn setTitle:@"Void Invoice" forState:UIControlStateNormal];
    // [VoidInVoiceBtn setBackgroundImage:[UIImage imageNamed:@"actionbuttons.png"] forState:UIControlStateNormal];
    [VoidInVoiceBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"actionbuttons" ofType:@"png"]] forState:UIControlStateNormal];
    VoidInVoiceBtn.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height+145,Vwidth-10, 40);
    
    [VoidInVoiceBtn addTarget:self action:@selector(VoidinVoiceClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [VoidInVoiceBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:VoidInVoiceBtn];
    
    
    SplitInvoiceBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [SplitInvoiceBtn setTitle:@"Split Invoice" forState:UIControlStateNormal];
    //[SplitInvoiceBtn setBackgroundImage:[UIImage imageNamed:@"actionbuttons.png"] forState:UIControlStateNormal];
    [SplitInvoiceBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"actionbuttons" ofType:@"png"]] forState:UIControlStateNormal];
    SplitInvoiceBtn.frame=CGRectMake(homewidth+20+VoidInVoiceBtn.frame.size.width,SubtotalView.frame.size.height+145,Vwidth-10, 40);
    
    //[SplitInvoiceBtn addTarget:self action:@selector(SplitInvoiceClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [SplitInvoiceBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:SplitInvoiceBtn];
    
    
    CGFloat Cashwidth=homewidth/3;
    
    
    
    CheckBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [CheckBtn setTitle:@"Cheque" forState:UIControlStateNormal];
    //[CheckBtn setBackgroundImage:[UIImage imageNamed:@"actionbuttons.png"] forState:UIControlStateNormal];
    [CheckBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"actionbuttons" ofType:@"png"]] forState:UIControlStateNormal];
    CheckBtn.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height+190,Cashwidth-10, 40);
    
    [CheckBtn addTarget:self action:@selector(CheckBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    [CheckBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:CheckBtn];
    
    CashBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [CashBtn setTitle:@"Cash" forState:UIControlStateNormal];
    //[CashBtn setBackgroundImage:[UIImage imageNamed:@"actionbuttons.png"] forState:UIControlStateNormal];
    [CashBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"actionbuttons" ofType:@"png"]] forState:UIControlStateNormal];
    CashBtn.frame=CGRectMake(homewidth+20+CheckBtn.frame.size.width,SubtotalView.frame.size.height+190,Cashwidth-10, 40);
    
    [CashBtn addTarget:self action:@selector(CashBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    
    
    [CashBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [HomebackView addSubview:CashBtn];
    
    CreditBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [CreditBtn setTitle:@"Card" forState:UIControlStateNormal];
    //[CreditBtn setBackgroundImage:[UIImage imageNamed:@"actionbuttons.png"] forState:UIControlStateNormal];
    [CreditBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"actionbuttons" ofType:@"png"]] forState:UIControlStateNormal];
    CreditBtn.frame=CGRectMake(homewidth+20+CheckBtn.frame.size.width+CashBtn.frame.size.width+10,SubtotalView.frame.size.height+190,Cashwidth-10, 40);
    
    [CreditBtn addTarget:self action:@selector(CreditBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    
    
    [CreditBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //CheckBtn.titleLabel.font=[UIFont systemFontOfSize:20.0f];
    [HomebackView addSubview:CreditBtn];
    
    DepartmentsTable = [[UITableView alloc] initWithFrame:CGRectMake(homewidth+10, SubtotalView.frame.size.height+235,156,HomebackView.frame.size.height-(SubtotalView.frame.size.height+240)) style:UITableViewStylePlain];
    
    DepartmentsTable.delegate = self;
    DepartmentsTable.dataSource = self;
    DepartmentsTable.scrollEnabled = YES;
    [HomebackView addSubview:DepartmentsTable];
    
  
   // if (!StoresArray)
    StoresArray=[[NSMutableArray alloc]init];
    if ([[generalDataObject  userType] isEqualToString:@"admin"])
    {
        NSString *querySQL5 = [NSString stringWithFormat: @"SELECT store_id FROM store_details"];
        NSMutableArray *storesArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL5 resultsArray:storesArray];
        
        for (NSDictionary *myDict in storesArray)
        {
            NSString *storeIDStr=[myDict objectForKey:@"store_id"];
            
            if ([storeIDStr length]>0)
            {
                [StoresArray addObject:storeIDStr];
            }
            storeIDStr=nil;
        }
        
    }
    else  if ([[generalDataObject  userType] isEqualToString:@"employee"])
    {
         NSString *querySQL = [NSString stringWithFormat: @"SELECT emp_store_id FROM employee_store "];
        NSMutableArray *empStoresArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:empStoresArray];
        
        for (NSDictionary *myDict in empStoresArray)
        {
            
            NSString *storeId=[myDict objectForKey:@"emp_store_id"];
            if ([storeId length]>0)
            {
                [StoresArray addObject:storeId];
            }
            storeId=nil;
        }
    }
    if ([StoresArray count]==1)
    {
        StoreID=[StoresArray objectAtIndex:0];
        
    }
    if ([StoresArray count]>1)
    {
        StoresPopupView=[[UIView alloc]init];
        if (isLandScope) {
            StoresPopupView.frame=CGRectMake(0, 0, 1024, 768);
        }
        
        else{
            
            StoresPopupView.frame=CGRectMake(0, 0, 768, 1024);
        }
        [StoresPopupView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
        [self.view addSubview:StoresPopupView];
        
        StoresView=[[UIView alloc] init];
        if (isLandScope) {
            StoresView.frame=CGRectMake(100, 200, StoresPopupView.frame.size.width-200, StoresPopupView.frame.size.height-400);
        }
        else
        {
            StoresView.frame=CGRectMake(50, 300, StoresPopupView.frame.size.width-100, StoresPopupView.frame.size.height-600);
        }
        
        
        [StoresView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
        [StoresView.layer setBorderWidth:4.0];
        [StoresView.layer setBorderColor:[[UIColor whiteColor] CGColor]];
        [StoresPopupView addSubview:StoresView];
        
        CGFloat widthfield4=(StoresView.frame.size.width)/4;
        SelectStorelbl=[[UILabel alloc] init];
        SelectStorelbl.frame=CGRectMake(20,20,widthfield4,40);
        [SelectStorelbl setFont:[UIFont systemFontOfSize:25.0f]];
        [SelectStorelbl setBackgroundColor:[UIColor clearColor]];
        [SelectStorelbl setTextColor:[UIColor whiteColor]];
        [SelectStorelbl setText:@"Select Store"];
        [SelectStorelbl setTextAlignment:NSTextAlignmentLeft];
        [StoresView addSubview:SelectStorelbl];
        
        SelectStoreBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        SelectStoreBtn.frame=CGRectMake(SelectStorelbl.frame.size.width+20, 20,widthfield4+10, 40);
        [SelectStoreBtn addTarget:self action:@selector(AddstoreClicked) forControlEvents:UIControlEventTouchUpInside];
        [SelectStoreBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        // [SelectStoreBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
        [SelectStoreBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"drop-down-icon" ofType:@"png"]] forState:UIControlStateNormal];
        [SelectStoreBtn setTitle:[StoresArray objectAtIndex:0] forState:UIControlStateNormal];
        [StoresView addSubview:SelectStoreBtn];
        
        
        StoresListTable = [[UITableView alloc] initWithFrame:CGRectMake(SelectStorelbl.frame.size.width+20, 60,widthfield4+10, 100) style:UITableViewStylePlain];
        StoresListTable.backgroundColor=[UIColor whiteColor];
        StoresListTable.delegate = self;
        StoresListTable.dataSource = self;
        StoresListTable.scrollEnabled = YES;
        StoresListTable.hidden=YES;
        [StoresListTable.layer setBorderWidth: 1.0];
        [StoresListTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
        [StoresView addSubview:StoresListTable];
        
        ProceedStoreBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        ProceedStoreBtn.frame=CGRectMake(widthfield4+120,300,80,30);
        [ProceedStoreBtn addTarget:self action:@selector(ProceedStore) forControlEvents:UIControlEventTouchUpInside];
        
        //[SaveTaxButton setTitle:@"Save" forState:UIControlStateNormal];
        [ProceedStoreBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        // [ProceedStoreBtn setBackgroundImage:[UIImage imageNamed:@"savegreenbutton.png"] forState:UIControlStateNormal];
        [ProceedStoreBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"savegreenbutton" ofType:@"png"]] forState:UIControlStateNormal];
        [StoresView addSubview:ProceedStoreBtn];
        
    }
    isLandScope = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
    //[NSTimer scheduledTimerWithTimeInterval:25.0f target:self selector:@selector(SendDeptPrintMethod) userInfo:nil repeats:YES];
    [self performSelector:@selector(SendDeptPrintMethod) withObject:nil afterDelay:25.0f];
    [NSThread detachNewThreadSelector:@selector(SendDeptPrintMethod) toTarget:self withObject:nil];
    if ([departmentsArray count]>0)
    {
        [DepartmentsTable reloadData];
        NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:0];
        [DepartmentsTable selectRowAtIndexPath:indexPath animated:NO  scrollPosition:UITableViewScrollPositionBottom];
        DepartmentsTable.backgroundColor=[UIColor colorWithRed:60.0f/255.0f green:101.0f/255.0f blue:134.0f/255.0f alpha:1.0f];
    }
    else
    {
        DepartmentsTable.backgroundColor=[UIColor colorWithRed:60.0f/255.0f green:101.0f/255.0f blue:134.0f/255.0f alpha:1.0f];
    }
    
    
    [self updateUI];
    
    
  
    RecallinvoiceValue=NO;
    
    [self PrinterDataMethod];
   
   /* ItemNosArray=nil;
    ItemNamesArray=nil;
    QntysArray=nil;
    pricesArray=nil;
    SnosArray=nil;
    TaxesArray=nil;
    AvegCostsArray=nil;
    DiscountsArray=nil;
    
    ItemDeptsArray=nil;
    ItemDesArray=nil;
    ItemVendorArray=nil;
    
    PrinterIpsArray=nil;
    printcharArray = nil;
    FontsArray = nil;
    AlignsArray = nil;
    languagesArray =nil;
    WidthsArray = nil;
    HeightsArray = nil;
    unitsArray = nil;
    boldsArray = nil;
    UnderlinesArray = nil;
    XpossArray = nil;
    
    spacingsArray = nil;
    printernamesArray = nil;
    IpAddsArray = nil;
    searchPrinterArray = nil;
    
    DBPrintertypesArray=nil;*/
    
    CustomerNO=@"101",CustomerName=@"cashcustomer";
    InVoiceCustomer=CustomerNO;

    
    ItemNosArray=[[NSMutableArray alloc]init];
    ItemNamesArray=[[NSMutableArray alloc]init];
    QntysArray=[[NSMutableArray alloc]init];
    pricesArray=[[NSMutableArray alloc]init];
    SnosArray=[[NSMutableArray alloc] init];
    TaxesArray=[[NSMutableArray alloc] init];
    AvegCostsArray=[[NSMutableArray alloc] init];
    DiscountsArray=[[NSMutableArray alloc] init];
    
    ItemDeptsArray=[[NSMutableArray alloc]init];
    ItemDesArray=[[NSMutableArray alloc] init];
    ItemVendorArray=[[NSMutableArray alloc] init];
    
    PrinterIpsArray=[[NSMutableArray alloc]init];
    printcharArray = [[NSMutableArray alloc]init];
    FontsArray = [[NSMutableArray alloc]init];
    AlignsArray = [[NSMutableArray alloc]init];
    languagesArray = [[NSMutableArray alloc]init];
    WidthsArray = [[NSMutableArray alloc]init];
    HeightsArray = [[NSMutableArray alloc]init];
    unitsArray = [[NSMutableArray alloc]init];
    boldsArray = [[NSMutableArray alloc]init];
    UnderlinesArray = [[NSMutableArray alloc]init];
    XpossArray = [[NSMutableArray alloc]init];
    
    spacingsArray = [[NSMutableArray alloc]init];
    printernamesArray = [[NSMutableArray alloc]init];
    IpAddsArray = [[NSMutableArray alloc]init];
    searchPrinterArray = [[NSMutableArray alloc]init];
    
    DBPrintertypesArray=[[NSMutableArray alloc]init];
    helpiconButton.hidden=YES;
}
-(void)cancelthethread
{
    if([[NSThread currentThread] isCancelled]) {
        /* do some clean up here */
        [NSThread exit];
    }
 
}
-(void)viewWillAppear:(BOOL)animated
{
    isLandScope = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
    [self updateUI];
    NSString *querySQL7 = [NSString stringWithFormat: @"SELECT check_value,department_id FROM department_details"];
    NSMutableArray *departmentDataArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL7 resultsArray:departmentDataArray];
  
    departmentsArray=[[NSMutableArray  alloc]init];
   
    productnosArray=[[NSMutableArray  alloc]init];
    
    for (NSDictionary *myDict in departmentDataArray)
    {
        
        NSString *check=[myDict objectForKey:@"check_value"];
        if ([check isEqualToString:@"true"]){
            [departmentsArray addObject:[myDict objectForKey:@"department_id"]];
            
        }
        check=nil;
    }
    NSString *querySQL = [NSString stringWithFormat:@"SELECT check_value,inventory_item_no,inventary_department,inventary_item_name FROM inventorytable"];
    NSMutableArray *productDataArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:productDataArray];
    
    
    for (NSDictionary *myDict in productDataArray)
    {
        
        NSString *check=[myDict objectForKey:@"check_value"];
        if ([check isEqualToString:@"true"])
        {
            [productnosArray addObject:[myDict objectForKey:@"inventory_item_no"]];
        }
        check=nil;
    }
   
    ItemsArray=[[NSMutableArray alloc]init];
    if ([departmentsArray count]>0){
        NSString *selectedstr=[departmentsArray objectAtIndex:0];
        
        for (NSDictionary *myDict in productDataArray)
        {
            NSString *valuesstr=[myDict objectForKey:@"inventary_department"];
            if ([valuesstr isEqualToString:selectedstr])
            {
                NSString *check=[myDict objectForKey:@"check_value"];
                if ([check isEqualToString:@"true"])
                {
                    [ItemsArray addObject:[myDict objectForKey:@"inventary_item_name"]];
                }
                check=nil;
            }
            valuesstr=nil;
        }
        selectedstr=nil;
    }
    
    NSArray *mainArray = itemsView.subviews;
    for (int i = 0; i<[mainArray count]; i++) {
        UIView *vi =[mainArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [ItemBtn removeFromSuperview];
    [itemsView removeFromSuperview];
    itemsView=nil,ItemBtn=nil;
    [self ItemsAddmethod];
    
    NSString *querySQL5 = [NSString stringWithFormat: @"SELECT headlines, language,unit,spacing,fontsize,align,Wsize,Hsize,bold,underline,Xposition,printname,print_id,ipaddress,printer_type,searchprinter FROM printer"];
    NSMutableArray *printersArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL5 resultsArray:printersArray];
    @autoreleasepool {
        for (NSDictionary *myDict in printersArray)
        {
            [PrinterIpsArray addObject:[myDict objectForKey:@"print_id"]];
            [printcharArray addObject:[myDict objectForKey:@"headlines"]];
            [FontsArray addObject:[myDict objectForKey:@"fontsize"]];
            [AlignsArray addObject:[myDict objectForKey:@"align"]];
            [languagesArray addObject:[myDict objectForKey:@"language"]];
            [WidthsArray addObject:[myDict objectForKey:@"Wsize"]];
            [HeightsArray addObject:[myDict objectForKey:@"Hsize"]];
            [boldsArray addObject:[myDict objectForKey:@"bold"]];
            [UnderlinesArray addObject:[myDict objectForKey:@"underline"]];
            [XpossArray addObject:[myDict objectForKey:@"Xposition"]];
            [unitsArray addObject:[myDict objectForKey:@"unit"]];
            
            [spacingsArray addObject:[myDict objectForKey:@"spacing"]];
            [printernamesArray addObject:[myDict objectForKey:@"printname"]];
            [IpAddsArray addObject:[myDict objectForKey:@"ipaddress"]];
            
            [DBPrintertypesArray addObject:[myDict objectForKey:@"printer_type"]];
            [searchPrinterArray addObject:[myDict objectForKey:@"searchprinter"]];
            
        }
        splitAmoutsArray=nil;
        SplitpaymentsArray=nil;
        [SplitDataTable reloadData];
        [self PrinterDataMethod];
    }
    

     [super viewWillAppear:YES];
   
   AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
     //NSLog(@"purchage amount %@",appDelegate.resultInf.amount);
    
    if ([appDelegate.resultInf.authAmount length]>0)
    {
        [self saveapproveCardDataMethod:appDelegate.resultInf.authAmount];
        
    }else if ([appDelegate.resultInf.amount length]>0)
    {
        [self saveapproveCardDataMethod:appDelegate.resultInf.amount];
    }
    appDelegate.resultInf.amount=@"";
    appDelegate.resultInf.authAmount=@"";
    appDelegate=nil;
    
   /* NSString *authAmout,*purchaseamount;
    NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory2 = [paths2 objectAtIndex:0];
    NSString *getImagePath = [documentsDirectory2 stringByAppendingPathComponent:@"authamount.txt"];
    
    authAmout = [NSString stringWithContentsOfFile:getImagePath encoding:NSUTF8StringEncoding error:nil];
     NSString *getImagePath2 = [documentsDirectory2 stringByAppendingPathComponent:@"amount.txt"];
    
    purchaseamount = [NSString stringWithContentsOfFile:getImagePath2 encoding:NSUTF8StringEncoding error:nil];
    
    if ([authAmout length]>0)
    {
        [self saveapproveCardDataMethod:authAmout];
        
    }else if ([purchaseamount length]>0)
    {
        [self saveapproveCardDataMethod:purchaseamount];
    }
    purchaseamount=@"",authAmout=@"";
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"amount.txt"];
    
    [purchaseamount writeToFile:filePath atomically:TRUE encoding:NSUTF8StringEncoding error:NULL];

    NSString *filePath2 = [documentsDirectory stringByAppendingPathComponent:@"authamount.txt"];
    
    [authAmout writeToFile:filePath2 atomically:TRUE encoding:NSUTF8StringEncoding error:NULL];*/
    
    
}

-(void)showTime
{
    
    NSDate *aDate = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterShortStyle];
    [formatter setTimeStyle:NSDateFormatterNoStyle];
    [formatter setDateFormat:@"HH:mm:ss"];
    NSString *datestr;
    datestr=[formatter stringFromDate:aDate];
    Timelbl.text=datestr;
     // Timelbl.text=[NSString stringWithFormat:@"%@:%@",@"Time",datestr];
    //Timelbl.text=[[NSDate date] description];
    
    
}
-(void)RecallInVoiceClicked
{
    [InVoiceIdsArray  removeAllObjects];
    [InVoiceIdsArray removeAllObjects];;
    
    [TotalAmountsArray removeAllObjects];;
    
    [paymentTypesArray removeAllObjects];;
    
   [HoldIdsArray removeAllObjects];;
    [TimesArray removeAllObjects];;
    
    [RsonsArray removeAllObjects];;
    InVoiceIdsArray=[[NSMutableArray alloc]init];
   
    TotalAmountsArray=[[NSMutableArray alloc]init];
    
    paymentTypesArray=[[NSMutableArray alloc]init];
   
    HoldIdsArray=[[NSMutableArray alloc]init];
   TimesArray=[[NSMutableArray alloc]init];
    
    RsonsArray=[[NSMutableArray alloc]init];
     [InVoiceIdsArray addObject:@""];
    [TotalAmountsArray addObject:@""];
    [paymentTypesArray addObject:@""];
    [TimesArray addObject:@""];

    
    NSString *querySQL = [NSString stringWithFormat: @"SELECT invoice_id,store_id,total_amt,status,payment_type,total_avgcost,total_profitt,unique_id,created_timestamp,holdid,employee,customer,cheque_no FROM invoice_total_table ORDER BY created_timestamp='%@' desc limit 10 offset 0 ",[generalDataObject getsystemDatetime]];
    NSMutableArray *invtotalDataArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:invtotalDataArray];
    
    querySQL=nil;
    @autoreleasepool {
    for (NSDictionary *myDict in invtotalDataArray)
    {
        NSString *Holdstr=[myDict objectForKey:@"status"];
        
        if ([Holdstr isEqualToString:@"complete"])
        {
            
            [RsonsArray addObject:[NSString stringWithFormat:@"%d",[InVoiceIdsArray count]]];
            [InVoiceIdsArray addObject:[myDict objectForKey:@"invoice_id"]];
            [TotalAmountsArray addObject:[myDict objectForKey:@"total_amt"]];
            
            [paymentTypesArray addObject:[myDict objectForKey:@"payment_type"]];
            [TimesArray addObject:[myDict objectForKey:@"created_timestamp"]];
        
        }
        Holdstr=nil;
    }
    }
    
    
    RecallViewpopup=[[UIView alloc]init];
    if (isLandScope){
        RecallViewpopup.frame=CGRectMake(0, 0, 1024, 768);
    }else{
        
        RecallViewpopup.frame=CGRectMake(0, 0, 768, 1024);
    }
    [RecallViewpopup setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:RecallViewpopup];
   
    RecallListTable = [[UITableView alloc] initWithFrame:CGRectMake(20,50, RecallViewpopup.frame.size.width-40,RecallViewpopup.frame.size.height-100)];
    RecallListTable.backgroundColor=[UIColor whiteColor];
    RecallListTable.delegate = self;
    RecallListTable.dataSource = self;
    RecallListTable.scrollEnabled = YES;
    [RecallViewpopup addSubview:RecallListTable];

}

-(void)PrintlastVoiceClicked
{
    
    NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES);
    NSString *documentsDirectory2 = [paths2 objectAtIndex:0];
    NSString *getImagePath = [documentsDirectory2 stringByAppendingPathComponent:@"Print.txt"];
    
    NSString *printstring;
    
    printstring = [NSString stringWithContentsOfFile:getImagePath encoding:NSUTF8StringEncoding error:nil];
    
    
  NSMutableString *stringToPrint=[[NSMutableString alloc]init];
    [stringToPrint setString:@" "];
     [stringToPrint appendFormat:@"%@",printstring];
   
        if ([PrinterIpsArray count]>0){
            [self PrinterDataMethod];
        }
    
    [self printImageMethod:&stringToPrint];
    printstring=nil,getImagePath=nil;
}

-(UIImage *) imageFromWebView:(UIWebView *)view
{
    // tempframe to reset view size after image was created
    CGRect tmpFrame         = view.frame;
    
    // set new Frame
    CGRect aFrame               = view.frame;
    aFrame.size.height  = [view sizeThatFits:[[UIScreen mainScreen] bounds].size].height;
    view.frame              = aFrame;
    
    // do image magic
    UIGraphicsBeginImageContext([view sizeThatFits:[[UIScreen mainScreen] bounds].size]);
    
    CGContextRef resizedContext = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:resizedContext];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    // reset Frame of view to origin
    view.frame = tmpFrame;
    return image;
}

- (void) drawPlaceholderInRect:(CGRect)rect {
    [[UIColor blueColor] setFill];
    [[QantyField placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:16]];
}
-(void)AddstoreClicked
{
    if (StoresListTable.hidden==1){
        StoresListTable.hidden=NO;
        
    }else if (StoresListTable.hidden==0)
    {
        [StoresListTable setHidden:YES];
    }
    
}
-(void)ProceedStore
{
    StoreID=[NSString stringWithFormat:@"%@",SelectStoreBtn.titleLabel.text];
    [StoresPopupView removeFromSuperview];
    
}
-(void)CreditBtnClicked
{
    
    if (RecallinvoiceValue==YES){
        [CheckBtn removeTarget:nil
                        action:NULL
              forControlEvents:UIControlEventAllEvents];
    }else{
    if ([[generalDataObject  userType] isEqualToString:@"employee"]){
        if ([[generalDataObject  force_credit_cards_permission] isEqualToString:@"yes"]){
            if ([ItemNamesArray count]>0)
            {
            NSString *amoutstr=GTotalDlbl.text;
            NSString *givenamtstr=GTotalDlbl.text;
            amoutstr = [amoutstr stringByReplacingOccurrencesOfString:@"$ " withString:@""];
            givenamtstr = [givenamtstr stringByReplacingOccurrencesOfString:@"$ " withString:@""];
            split_amount=givenamtstr;
            
            
            amount=[amoutstr doubleValue];
            givenamout=[givenamtstr doubleValue];
            
            [self CreditTypepaymentMethod];
                amoutstr=nil,givenamtstr=nil;
          }else{
           
                [self.view makeToast:@"Please Add The Items."];
           }
        
        }else{
            UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
            
            [authalert show];
            authalert=nil;
        }
    }
else
{    if ([ItemNamesArray count]>0)
    {
    NSString *amoutstr=GTotalDlbl.text;
    NSString *givenamtstr=GTotalDlbl.text;
    amoutstr = [amoutstr stringByReplacingOccurrencesOfString:@"$ " withString:@""];
    givenamtstr = [givenamtstr stringByReplacingOccurrencesOfString:@"$ " withString:@""];
    split_amount=givenamtstr;
    
    
    amount=[amoutstr doubleValue];
    givenamout=[givenamtstr doubleValue];
    [self CreditTypepaymentMethod];
        amoutstr=nil,givenamtstr=nil;
    
    }else{
         [self.view makeToast:@"Please Add The Items."];
    }
   }
    
  }
}
-(void)CheckBtnClicked
{
    
    if (RecallinvoiceValue==YES){
        [CheckBtn removeTarget:nil
                              action:NULL
                    forControlEvents:UIControlEventAllEvents];
    }else{
        if ([ItemNamesArray count]>0){
            
        //NSString *amoutstr=GTotalDlbl.text;
        NSString *givenamtstr=GTotalDlbl.text;
        //amoutstr = [amoutstr stringByReplacingOccurrencesOfString:@"$ " withString:@""];
        givenamtstr = [givenamtstr stringByReplacingOccurrencesOfString:@"$ " withString:@""];
        split_amount=givenamtstr;
        
        [self CheckTypePaymentMethod];
            givenamtstr=nil;
        
       }else{
    
            [self.view makeToast:@"Please Add The Items."];
       }
    }
    
}
-(void)CashBtnClicked
{
    
if (RecallinvoiceValue==YES){
    [CashBtn removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents];
}
else{
  if ([[generalDataObject  userType] isEqualToString:@"employee"]){
    if ([[generalDataObject  end_cash_transaction_permission] isEqualToString:@"yes"]){
        
        if ([ItemNamesArray count]>0){
           [self PayBtnClicked];
        }else{
            
            [self.view makeToast:@"Please Add The Items."];
        }
    
    }else
    {
        UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
        
        [authalert show];
        authalert=nil;
    }
   }
  else{
    
     if ([ItemNamesArray count]>0){
         [self PayBtnClicked];
     
     }else{
         [self.view makeToast:@"Please Add The Items."];
    }
    
  }
 }
}
-(void)CustomerBtnClicked
{
    Customernamelbl.text=[NSString stringWithFormat:@"%@%@",@"Customer Name=",CustomerName];
    CustomerNolbl.text=[NSString stringWithFormat:@"%@%@",@"CustomerNumber=",CustomerNO];
}
-(void)CustomerInfoClicked
{
    //NSLog(@"customer%@",CusomerCompany);
    //NSLog(@"%@",CustomerPhoneNumber);
    if (CusomerCompany == (id)[NSNull null] || CusomerCompany.length == 0 ) CusomerCompany = @"Something";
    {
         CusomerCompany=@" ";
    }
    if (CustomerPhoneNumber == (id)[NSNull null] || CustomerPhoneNumber.length == 0 ) CustomerPhoneNumber = @"Something";
    {
        CustomerPhoneNumber=@" ";
    }
    Customernamelbl.text=[NSString stringWithFormat:@"%@%@",@"Customer Company=",CusomerCompany];
    CustomerNolbl.text=[NSString stringWithFormat:@"%@%@",@"CustomerPhNo=",CustomerPhoneNumber];
    
}
-(void)AddCustomerClicked
{
     NSArray *viewS = [self.navigationController viewControllers];
    if (RecallinvoiceValue==YES){
        [AddBtn removeTarget:nil
                         action:NULL
               forControlEvents:UIControlEventAllEvents];
    }else if (RecallinvoiceValue==NO){
        
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  customer_permission] isEqualToString:@"yes"])
            {
                NSString *returnvalue;
                NSInteger selectedview;
                Customers *customersview=[[Customers alloc]initWithNibName:@"Customers" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Customers class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                    
                    [self.navigationController pushViewController:customersview animated:NO];
                    [self releaseViews];
                }
                
            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }else{
            
            NSString *returnvalue;
            NSInteger selectedview;
            Customers *customersview=[[Customers alloc]initWithNibName:@"Customers" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Customers class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:customersview animated:NO];
                [self releaseViews];
            }
        }
    }
}

-(void)FetchOnHoldClicked
{
    
    if (RecallinvoiceValue==YES){
        [retraiveOnHoldBtn removeTarget:nil
                           action:NULL
                 forControlEvents:UIControlEventAllEvents];
    }else{
    if ([[generalDataObject  userType] isEqualToString:@"employee"])
    {
        if ([[generalDataObject  hold_print_permission] isEqualToString:@"yes"])
        {
            NSString *string=[NSString stringWithFormat:@"%@",retraiveOnHoldBtn.titleLabel.text];
            
            if ([string isEqualToString:@"Fetch on Hold"])
            {
                HoldID=@"";
                invoiceID=@"";
                if (!FetchOnHoldBackView)
                FetchOnHoldBackView=[[UIView alloc]init];
                if (isLandScope) {
                    FetchOnHoldBackView.frame=CGRectMake(0, 0, 1024, 768);
                }
                
                else{
                    
                    FetchOnHoldBackView.frame=CGRectMake(0, 0, 768, 1024);
                }
                [FetchOnHoldBackView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
                [self.view addSubview:FetchOnHoldBackView];
                
                if (!FetchOnHoldView)
                FetchOnHoldView=[[UIView alloc]init];
                FetchOnHoldView.frame=CGRectMake(20,100, FetchOnHoldBackView.frame.size.width-40, FetchOnHoldBackView.frame.size.height-200);
                
                [FetchOnHoldView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
                [FetchOnHoldView.layer setBorderWidth:2.0];
                [FetchOnHoldView.layer setBorderColor:[[UIColor blackColor] CGColor]];
                //AddvendorsView.layer.cornerRadius=8;
                [FetchOnHoldBackView addSubview:FetchOnHoldView];
                
                CGFloat Fwidth=(FetchOnHoldView.frame.size.width)/2;
                if (!Fetchlbl)
                Fetchlbl=[[UILabel alloc] init];
                Fetchlbl.frame=CGRectMake(Fwidth-60, 25,Fwidth, 50);
                [Fetchlbl setFont:[UIFont systemFontOfSize:25.0f]];
                [Fetchlbl setBackgroundColor:[UIColor clearColor]];
                [Fetchlbl setTextColor:[UIColor whiteColor]];
                [Fetchlbl setText:@"Hold-Details"];
                Fetchlbl.lineBreakMode = NSLineBreakByWordWrapping;
                Fetchlbl.numberOfLines = 2;
                [Fetchlbl setTextAlignment:NSTextAlignmentLeft];
                [FetchOnHoldView addSubview:Fetchlbl];
                
                if (!FecthOnHoldlistTable)
                FecthOnHoldlistTable = [[UITableView alloc] initWithFrame:CGRectMake(0,100, FetchOnHoldView.frame.size.width,FetchOnHoldView.frame.size.height-100)];
                FecthOnHoldlistTable.backgroundColor=[UIColor whiteColor];
                FecthOnHoldlistTable.delegate = self;
                FecthOnHoldlistTable.dataSource = self;
                FecthOnHoldlistTable.scrollEnabled = YES;
                [FetchOnHoldView addSubview:FecthOnHoldlistTable];
                
                InVoiceIdsArray=[[NSMutableArray alloc]init];
                TotalAmountsArray=[[NSMutableArray alloc]init];
                StatusArray=[[NSMutableArray alloc]init];
                HoldIdsArray=[[NSMutableArray alloc]init];
                TimesArray=[[NSMutableArray alloc]init];
                CustomersArray=[[NSMutableArray alloc]init];
                EmployeesArray=[[NSMutableArray alloc]init];
                
                
              NSString *querySQL = [NSString stringWithFormat: @"SELECT invoice_id,store_id,total_amt,status,payment_type,total_avgcost,total_profitt,unique_id,created_timestamp,holdid,employee,customer,cheque_no FROM invoice_total_table WHERE status='%@'",@"hold"];
                
                NSMutableArray *totalinvArray=[[NSMutableArray alloc]init];
                [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:totalinvArray];
                                             
                querySQL=nil;
                @autoreleasepool {
                for (NSDictionary *myDict in totalinvArray)
                {
                    NSString *Holdstr=[myDict objectForKey:@"status"];
                    
                    if ([Holdstr isEqualToString:@"hold"])
                    {
                        [InVoiceIdsArray addObject:[myDict objectForKey:@"invoice_id"]];
                        [TotalAmountsArray addObject:[myDict objectForKey:@"total_amt"]];
                        
                        [HoldIdsArray addObject:[myDict objectForKey:@"holdid"]];
                        [TimesArray addObject:[myDict objectForKey:@"created_timestamp"]];
                        [CustomersArray addObject:[myDict objectForKey:@"customer"]];
                        [EmployeesArray addObject:[myDict objectForKey:@"employee"]];
                        
                    }
                }
                    [FecthOnHoldlistTable reloadData];
            }
      
        }else if ([string isEqualToString:@"Save on Hold"])
            {
                if ([HoldID length]>0)
                {
                    HoldStatus=@"hold";
                    [self ProductPrinterMethod];
                    
                    [self UpdateInVoiceDataMethod];
                    
                   // [self SaveInvoiceDataMethod];
                    
                    [ItemNamesArray removeAllObjects];
                    [ItemNosArray removeAllObjects];
                    [QntysArray removeAllObjects];
                    [pricesArray removeAllObjects];
                    [SnosArray removeAllObjects];
                    [TaxesArray removeAllObjects];
                    [AvegCostsArray removeAllObjects];
                    [DiscountsArray removeAllObjects];
                    
                    [ItemVendorArray removeAllObjects];
                    [ItemDeptsArray removeAllObjects];
                    [ItemDesArray removeAllObjects];
                    
                    [ProductslistTable reloadData];
                    SubTDisplaylbl.text=@"$ 0.00";
                    taxDlbl.text=@"$ 0.00";
                    GTotalDlbl.text=@"$ 0.00";
                    [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                }
                else
                {
                    if (!QuantityPopupView)
                    QuantityPopupView=[[UIView alloc]init];
                    if (isLandScope) {
                        QuantityPopupView.frame=CGRectMake(0, 0, 1024, 768);
                    }
                    
                    else{
                        
                        QuantityPopupView.frame=CGRectMake(0, 0, 768, 1024);
                    }
                    [QuantityPopupView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
                    [self.view addSubview:QuantityPopupView];
                    
                    if (!Quantityview)
                    Quantityview=[[UIScrollView alloc]init];
                    if (isLandScope)
                    {
                        Quantityview.frame=CGRectMake(200, 200, QuantityPopupView.frame.size.width-400, QuantityPopupView.frame.size.height-450);
                    }
                    else
                    {
                        Quantityview.frame=CGRectMake(150, 300, QuantityPopupView.frame.size.width-300, QuantityPopupView.frame.size.height-750);
                    }
                    
                    [Quantityview setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
                    
                    [Quantityview.layer setBorderWidth:2.0];
                    [Quantityview.layer setBorderColor:[[UIColor whiteColor] CGColor]];
                    //AddvendorsView.layer.cornerRadius=8;
                    [QuantityPopupView addSubview:Quantityview];
                    
                    
                    CGFloat instwidth=(Quantityview.frame.size.width)/2;
                    CGFloat inst=instwidth/2;
                    
                    if (!QTextlbl)
                    QTextlbl=[[UILabel alloc] init];
                    QTextlbl.frame=CGRectMake(10, 25,Quantityview.frame.size.width-20, 50);
                    [QTextlbl setFont:[UIFont systemFontOfSize:25.0f]];
                    [QTextlbl setBackgroundColor:[UIColor clearColor]];
                    [QTextlbl setTextColor:[UIColor whiteColor]];
                    [QTextlbl setText:@"Enter Hold Id"];
                    QTextlbl.lineBreakMode = NSLineBreakByWordWrapping;
                    QTextlbl.numberOfLines = 2;
                    [QTextlbl setTextAlignment:NSTextAlignmentLeft];
                    [Quantityview addSubview:QTextlbl];
                    
                    if (!ChangeQuantityField)
                    ChangeQuantityField=[[UITextField alloc] init];
                    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
                    ChangeQuantityField.frame=CGRectMake(20, 95,instwidth+50, 40);
                    ChangeQuantityField.delegate=self;
                    
                    UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
                    // // //NSLog(@"%f",GeneralinfoField.frame.origin.y);
                    ChangeQuantityField.leftView = paddingview;
                    ChangeQuantityField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
                    ChangeQuantityField.leftViewMode = UITextFieldViewModeAlways;
                   // [ChangeQuantityField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
                    [ChangeQuantityField setBackground:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"addinputtextfield" ofType:@"png"]]];

                    [ChangeQuantityField setAutocorrectionType:UITextAutocorrectionTypeNo];
                    [Quantityview addSubview:ChangeQuantityField];
                    
                    if (!SaveQtyBtn)
                    SaveQtyBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                    SaveQtyBtn.frame=CGRectMake(ChangeQuantityField.frame.size.width+40, 105, 80, 30);
                    [SaveQtyBtn addTarget:self action:@selector(SaveHoldData) forControlEvents:UIControlEventTouchUpInside];
                    [SaveQtyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                   // [SaveQtyBtn setBackgroundImage:[UIImage imageNamed:@"savegreenbutton.png"] forState:UIControlStateNormal];
                    [SaveQtyBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"savegreenbutton" ofType:@"png"]] forState:UIControlStateNormal];
                    [Quantityview addSubview:SaveQtyBtn];
                    
                    if (!PrintatDeptlbl)
                    PrintatDeptlbl=[[UILabel alloc] init];
                    PrintatDeptlbl.frame=CGRectMake(inst-60,160,instwidth+20, 50);
                    
                    [PrintatDeptlbl setFont:[UIFont systemFontOfSize:25.0f]];
                    [PrintatDeptlbl setBackgroundColor:[UIColor clearColor]];
                    [PrintatDeptlbl setTextColor:[UIColor whiteColor]];
                    [PrintatDeptlbl setText:@"Print at Departments"];
                    PrintatDeptlbl.lineBreakMode = NSLineBreakByWordWrapping;
                    PrintatDeptlbl.numberOfLines = 2;
                    [PrintatDeptlbl setTextAlignment:NSTextAlignmentLeft];
                   // [Quantityview addSubview:PrintatDeptlbl];
                    
                    if (!PrintDeptSwitch)
                    PrintDeptSwitch=[[UISwitch alloc] init];
                    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
                    PrintDeptSwitch.frame=CGRectMake(PrintatDeptlbl.frame.size.width+60,172,100,40);
                    
                    [PrintDeptSwitch addTarget:self action:@selector(MyswitchClicked2:) forControlEvents:UIControlEventValueChanged];
                    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
                    NSString *documentsDirectory = [paths objectAtIndex:0];
                    NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"switch.txt"];
                    
                    DeptSwitchValue = [NSString stringWithContentsOfFile:getImagePath encoding:NSUTF8StringEncoding error:nil];
                    
                    if ([DeptSwitchValue length]==0)
                    {
                        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                        NSString *documentsDirectory = [paths objectAtIndex:0];
                        NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"switch.txt"];
                        
                        DeptSwitchValue = @"OFF";
                        
                        [DeptSwitchValue writeToFile:filePath atomically:TRUE encoding:NSUTF8StringEncoding error:NULL];
                    }
                    
                    if ([DeptSwitchValue isEqualToString:@"ON"]){
                        [PrintDeptSwitch setOn:TRUE animated:YES];
                    
                    }else{
                        [PrintDeptSwitch setOn:FALSE animated:YES];
                     
                    }
                    if (!Swicthtextlbl)
                    Swicthtextlbl=[[UILabel alloc] init];
                    Swicthtextlbl.frame=CGRectMake(PrintatDeptlbl.frame.size.width+60,210,100,40);
                    [Swicthtextlbl setFont:[UIFont systemFontOfSize:25.0f]];
                    [Swicthtextlbl setBackgroundColor:[UIColor clearColor]];
                    [Swicthtextlbl setTextColor:[UIColor whiteColor]];
                    [Swicthtextlbl setText:DeptSwitchValue];
                    Swicthtextlbl.lineBreakMode = NSLineBreakByWordWrapping;
                    Swicthtextlbl.numberOfLines = 2;
                    [Swicthtextlbl setTextAlignment:NSTextAlignmentLeft];
               
                }
            }

            string=nil;
        }
        else
        {
            UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
            
            [authalert show];
            authalert=nil;
        }
}else{
    
    NSString *string=[NSString stringWithFormat:@"%@",retraiveOnHoldBtn.titleLabel.text];
    
    if ([string isEqualToString:@"Fetch on Hold"])
    {
        HoldID=@"";
        invoiceID=@"";
        if (!FetchOnHoldBackView)
            FetchOnHoldBackView=[[UIView alloc]init];
        if (isLandScope) {
            FetchOnHoldBackView.frame=CGRectMake(0, 0, 1024, 768);
        }
        
        else{
            
            FetchOnHoldBackView.frame=CGRectMake(0, 0, 768, 1024);
        }
        [FetchOnHoldBackView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
        [self.view addSubview:FetchOnHoldBackView];
        
        if (!FetchOnHoldView)
            FetchOnHoldView=[[UIView alloc]init];
        FetchOnHoldView.frame=CGRectMake(20,100, FetchOnHoldBackView.frame.size.width-40, FetchOnHoldBackView.frame.size.height-200);
        
        [FetchOnHoldView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
        [FetchOnHoldView.layer setBorderWidth:2.0];
        [FetchOnHoldView.layer setBorderColor:[[UIColor blackColor] CGColor]];
        //AddvendorsView.layer.cornerRadius=8;
        [FetchOnHoldBackView addSubview:FetchOnHoldView];
        
        CGFloat Fwidth=(FetchOnHoldView.frame.size.width)/2;
        if (!Fetchlbl)
            Fetchlbl=[[UILabel alloc] init];
        Fetchlbl.frame=CGRectMake(Fwidth-60, 25,Fwidth, 50);
        [Fetchlbl setFont:[UIFont systemFontOfSize:25.0f]];
        [Fetchlbl setBackgroundColor:[UIColor clearColor]];
        [Fetchlbl setTextColor:[UIColor whiteColor]];
        [Fetchlbl setText:@"Hold-Details"];
        Fetchlbl.lineBreakMode = NSLineBreakByWordWrapping;
        Fetchlbl.numberOfLines = 2;
        [Fetchlbl setTextAlignment:NSTextAlignmentLeft];
        [FetchOnHoldView addSubview:Fetchlbl];
        
        if (!FecthOnHoldlistTable)
            FecthOnHoldlistTable = [[UITableView alloc] initWithFrame:CGRectMake(0,100, FetchOnHoldView.frame.size.width,FetchOnHoldView.frame.size.height-100)];
        FecthOnHoldlistTable.backgroundColor=[UIColor whiteColor];
        FecthOnHoldlistTable.delegate = self;
        FecthOnHoldlistTable.dataSource = self;
        FecthOnHoldlistTable.scrollEnabled = YES;
        [FetchOnHoldView addSubview:FecthOnHoldlistTable];
        
        InVoiceIdsArray=[[NSMutableArray alloc]init];
        TotalAmountsArray=[[NSMutableArray alloc]init];
        StatusArray=[[NSMutableArray alloc]init];
        HoldIdsArray=[[NSMutableArray alloc]init];
        TimesArray=[[NSMutableArray alloc]init];
        CustomersArray=[[NSMutableArray alloc]init];
        EmployeesArray=[[NSMutableArray alloc]init];
        
        
        NSString *querySQL = [NSString stringWithFormat: @"SELECT invoice_id,store_id,total_amt,status,payment_type,total_avgcost,total_profitt,unique_id,created_timestamp,holdid,employee,customer,cheque_no FROM invoice_total_table WHERE status='%@'",@"hold"];
        NSMutableArray *totalinvArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:totalinvArray];
        
        querySQL=nil;
        @autoreleasepool {
            for (NSDictionary *myDict in totalinvArray)
            {
                NSString *Holdstr=[myDict objectForKey:@"status"];
                
                if ([Holdstr isEqualToString:@"hold"])
                {
                    [InVoiceIdsArray addObject:[myDict objectForKey:@"invoice_id"]];
                    [TotalAmountsArray addObject:[myDict objectForKey:@"total_amt"]];
                    
                    [HoldIdsArray addObject:[myDict objectForKey:@"holdid"]];
                    [TimesArray addObject:[myDict objectForKey:@"created_timestamp"]];
                    [CustomersArray addObject:[myDict objectForKey:@"customer"]];
                    [EmployeesArray addObject:[myDict objectForKey:@"employee"]];
                    
                }
            }
        }
          [FecthOnHoldlistTable reloadData];
        
    }else if ([string isEqualToString:@"Save on Hold"])
    {
        if ([HoldID length]>0)
        {
            HoldStatus=@"hold";
            [self ProductPrinterMethod];
            
            [self UpdateInVoiceDataMethod];
            
            // [self SaveInvoiceDataMethod];
            
            [ItemNamesArray removeAllObjects];
            [ItemNosArray removeAllObjects];
            [QntysArray removeAllObjects];
            [pricesArray removeAllObjects];
            [SnosArray removeAllObjects];
            [TaxesArray removeAllObjects];
            [AvegCostsArray removeAllObjects];
            [DiscountsArray removeAllObjects];
            
            [ItemVendorArray removeAllObjects];
            [ItemDeptsArray removeAllObjects];
            [ItemDesArray removeAllObjects];
            
            [ProductslistTable reloadData];
            SubTDisplaylbl.text=@"$ 0.00";
            taxDlbl.text=@"$ 0.00";
            GTotalDlbl.text=@"$ 0.00";
            [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
        }
        else
        {
            if (!QuantityPopupView)
                QuantityPopupView=[[UIView alloc]init];
            if (isLandScope) {
                QuantityPopupView.frame=CGRectMake(0, 0, 1024, 768);
            }
            
            else{
                
                QuantityPopupView.frame=CGRectMake(0, 0, 768, 1024);
            }
            [QuantityPopupView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
            [self.view addSubview:QuantityPopupView];
            
            if (!Quantityview)
                Quantityview=[[UIScrollView alloc]init];
            if (isLandScope)
            {
                Quantityview.frame=CGRectMake(200, 200, QuantityPopupView.frame.size.width-400, QuantityPopupView.frame.size.height-450);
            }
            else
            {
                Quantityview.frame=CGRectMake(150, 300, QuantityPopupView.frame.size.width-300, QuantityPopupView.frame.size.height-750);
            }
            
            [Quantityview setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
            
            [Quantityview.layer setBorderWidth:2.0];
            [Quantityview.layer setBorderColor:[[UIColor whiteColor] CGColor]];
            //AddvendorsView.layer.cornerRadius=8;
            [QuantityPopupView addSubview:Quantityview];
            
            
            CGFloat instwidth=(Quantityview.frame.size.width)/2;
            CGFloat inst=instwidth/2;
            
            if (!QTextlbl)
                QTextlbl=[[UILabel alloc] init];
            QTextlbl.frame=CGRectMake(10, 25,Quantityview.frame.size.width-20, 50);
            [QTextlbl setFont:[UIFont systemFontOfSize:25.0f]];
            [QTextlbl setBackgroundColor:[UIColor clearColor]];
            [QTextlbl setTextColor:[UIColor whiteColor]];
            [QTextlbl setText:@"Enter Hold Id"];
            QTextlbl.lineBreakMode = NSLineBreakByWordWrapping;
            QTextlbl.numberOfLines = 2;
            [QTextlbl setTextAlignment:NSTextAlignmentLeft];
            [Quantityview addSubview:QTextlbl];
            
            if (!ChangeQuantityField)
                ChangeQuantityField=[[UITextField alloc] init];
            //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
            ChangeQuantityField.frame=CGRectMake(20, 95,instwidth+50, 40);
            ChangeQuantityField.delegate=self;
            
            UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
            // // //NSLog(@"%f",GeneralinfoField.frame.origin.y);
            ChangeQuantityField.leftView = paddingview;
            ChangeQuantityField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
            ChangeQuantityField.leftViewMode = UITextFieldViewModeAlways;
            // [ChangeQuantityField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
            [ChangeQuantityField setBackground:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"addinputtextfield" ofType:@"png"]]];
            
            [ChangeQuantityField setAutocorrectionType:UITextAutocorrectionTypeNo];
            [Quantityview addSubview:ChangeQuantityField];
            
            if (!SaveQtyBtn)
                SaveQtyBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            SaveQtyBtn.frame=CGRectMake(ChangeQuantityField.frame.size.width+40, 105, 80, 30);
            [SaveQtyBtn addTarget:self action:@selector(SaveHoldData) forControlEvents:UIControlEventTouchUpInside];
            [SaveQtyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            // [SaveQtyBtn setBackgroundImage:[UIImage imageNamed:@"savegreenbutton.png"] forState:UIControlStateNormal];
            [SaveQtyBtn setBackgroundImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"savegreenbutton" ofType:@"png"]] forState:UIControlStateNormal];
            [Quantityview addSubview:SaveQtyBtn];
            
            if (!PrintatDeptlbl)
                PrintatDeptlbl=[[UILabel alloc] init];
            PrintatDeptlbl.frame=CGRectMake(inst-60,160,instwidth+20, 50);
            
            [PrintatDeptlbl setFont:[UIFont systemFontOfSize:25.0f]];
            [PrintatDeptlbl setBackgroundColor:[UIColor clearColor]];
            [PrintatDeptlbl setTextColor:[UIColor whiteColor]];
            [PrintatDeptlbl setText:@"Print at Departments"];
            PrintatDeptlbl.lineBreakMode = NSLineBreakByWordWrapping;
            PrintatDeptlbl.numberOfLines = 2;
            [PrintatDeptlbl setTextAlignment:NSTextAlignmentLeft];
            // [Quantityview addSubview:PrintatDeptlbl];
            
            if (!PrintDeptSwitch)
                PrintDeptSwitch=[[UISwitch alloc] init];
            //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
            PrintDeptSwitch.frame=CGRectMake(PrintatDeptlbl.frame.size.width+60,172,100,40);
            
            [PrintDeptSwitch addTarget:self action:@selector(MyswitchClicked2:) forControlEvents:UIControlEventValueChanged];
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
            NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"switch.txt"];
            
            DeptSwitchValue = [NSString stringWithContentsOfFile:getImagePath encoding:NSUTF8StringEncoding error:nil];
            
            if ([DeptSwitchValue length]==0)
            {
                NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                NSString *documentsDirectory = [paths objectAtIndex:0];
                NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"switch.txt"];
                
                DeptSwitchValue = @"OFF";
                
                [DeptSwitchValue writeToFile:filePath atomically:TRUE encoding:NSUTF8StringEncoding error:NULL];
            }
            
            if ([DeptSwitchValue isEqualToString:@"ON"]){
                [PrintDeptSwitch setOn:TRUE animated:YES];
                
            }else{
                [PrintDeptSwitch setOn:FALSE animated:YES];
                
            }
            if (!Swicthtextlbl)
                Swicthtextlbl=[[UILabel alloc] init];
            Swicthtextlbl.frame=CGRectMake(PrintatDeptlbl.frame.size.width+60,210,100,40);
            [Swicthtextlbl setFont:[UIFont systemFontOfSize:25.0f]];
            [Swicthtextlbl setBackgroundColor:[UIColor clearColor]];
            [Swicthtextlbl setTextColor:[UIColor whiteColor]];
            [Swicthtextlbl setText:DeptSwitchValue];
            Swicthtextlbl.lineBreakMode = NSLineBreakByWordWrapping;
            Swicthtextlbl.numberOfLines = 2;
            [Swicthtextlbl setTextAlignment:NSTextAlignmentLeft];
            
        }
    }
    
    string=nil;
   }
   }
}
-(void)SaveHoldData
{
    //NSString *HoldID,*InVoiceId;

    HoldIdsArray=[[NSMutableArray alloc]init];
    
    NSString *querySQL2 = [NSString stringWithFormat: @"SELECT status,holdid FROM invoice_total_table"];
    NSMutableArray *totalinvArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL2 resultsArray:totalinvArray];
    
   
    querySQL2=nil;
    
    for (NSDictionary *myDict in totalinvArray)
    {
        NSString *Holdstr=[myDict objectForKey:@"status"];
        
        if ([Holdstr isEqualToString:@"hold"])
        {
            
            [HoldIdsArray addObject:[myDict objectForKey:@"holdid"]];
        }
        Holdstr=nil;
    }
    NSUInteger objIdx = [HoldIdsArray containsObject:ChangeQuantityField.text];
    //// //NSLog(@"%lu",(unsigned long)objIdx);
    if(objIdx == 0)
    {
        HoldID=ChangeQuantityField.text;
        invoiceID=[generalDataObject  getDeviceID];
        HoldStatus=@"hold";
        [self ProductPrinterMethod];
        
        [self SaveInvoiceDataMethod];
        [self releaseAllviewsmethod];
         [self qtyViewremoveMethod];
        
        [ItemNamesArray removeAllObjects];
        [ItemNosArray removeAllObjects];
        [QntysArray removeAllObjects];
        [pricesArray removeAllObjects];
        [SnosArray removeAllObjects];
        [TaxesArray removeAllObjects];
        [AvegCostsArray removeAllObjects];
        [DiscountsArray removeAllObjects];
        
        [ItemVendorArray removeAllObjects];
        [ItemDeptsArray removeAllObjects];
        [ItemDesArray removeAllObjects];
        
        [ProductslistTable reloadData];
        SubTDisplaylbl.text=@"$ 0.00";
        taxDlbl.text=@"$ 0.00";
        GTotalDlbl.text=@"$ 0.00";
        [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
    }
 else
 {
     UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"message" message:@"Hold ID already exit change the hold ID" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
     [alert show];
     alert=nil;
     
 }
    
    PrinterHoldID=[[NSString alloc]init];
    PrinterHoldID=HoldID;
    
    //HoldID=@"";
    //invoiceID=@"";
    
}
-(NSString *)PrinterExitmethod
{
   
    NSString *printerexit;
    
    for (int i=0; i<[ItemNosArray count]; i++)
    {
        NSString *Dept=[ItemDeptsArray objectAtIndex:i];
        
        NSString *querySQL = [NSString stringWithFormat: @"SELECT department_id FROM department_printer_commands WHERE department_id='%@'",Dept];
        NSMutableArray *deptprinterArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:deptprinterArray];
        
            if ([deptprinterArray count]>0)
            {
                printerexit=@"yes";
                break;
            }
        Dept=nil;
    }
    
    return printerexit;
    
}
-(void)ProductPrinterMethod
{
    NSString *PrinterexistStr=[self PrinterExitmethod];
    
    if ([PrinterexistStr isEqualToString:@"yes"])
    {

    ProductNamesArray=[[NSMutableArray alloc]init];
    //ProductNamesArray=ItemNamesArray;
    DepPrinterDataArray=[[NSMutableArray alloc]init];
    DepTimesArray=[[NSMutableArray alloc]init];
    QtyitemsArry=[[NSMutableArray alloc]init];
    for (int i=0; i<[ItemDeptsArray count]; i++)
    {
        NSString *Dept=[ItemDeptsArray objectAtIndex:i];
        
        NSString *querySQL = [NSString stringWithFormat: @"SELECT department_id,department_printer,department_print_time FROM department_printer_commands WHERE department_id='%@'",Dept];
        NSMutableArray *deptprinterArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:deptprinterArray];
        
        if ([deptprinterArray count]<=0){
              [DepPrinterDataArray addObject:@""];
              [DepTimesArray addObject:@""];
        }else{
        for (NSDictionary *myDict in deptprinterArray)
        {
            NSString *printer=[myDict objectForKey:@"department_printer"];
           
                [DepPrinterDataArray addObject:printer];
                
          
            
             NSString *time=[myDict objectForKey:@"department_print_time"];
            
             NSArray *array=[time componentsSeparatedByString:@":"];
              time=[array objectAtIndex:0];
            [DepTimesArray addObject:time];
            time=nil;
        }
    }
        
        
        NSString *item=[ItemNamesArray objectAtIndex:i];
        [ProductNamesArray addObject:item];
        
        NSString *qty=[QntysArray objectAtIndex:i];
        [QtyitemsArry addObject:[NSString stringWithFormat:@"%@ %@",qty,item]];
        item=nil,qty=nil;
        
    }
   
        if (!ProductPrinterPopUp)
        ProductPrinterPopUp=[[UIView alloc]init];
        if (isLandScope) {
            ProductPrinterPopUp.frame=CGRectMake(0, 0, 1024, 768);
        }
        
        else{
            
            ProductPrinterPopUp.frame=CGRectMake(0, 0, 768, 1024);
        }
        [ProductPrinterPopUp setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
        [self.view addSubview:ProductPrinterPopUp];
        
        if (!ProductPrinterView)
        ProductPrinterView=[[UIScrollView alloc]init];
        ProductPrinterView.frame=CGRectMake(20, 100, ProductPrinterPopUp.frame.size.width-40, ProductPrinterPopUp.frame.size.height-200);
        [ProductPrinterView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
        ProductPrinterView.contentSize=CGSizeMake(ProductPrinterPopUp.frame.size.width-40, ProductPrinterPopUp.frame.size.height+300);
        [ProductPrinterView.layer setBorderWidth:2.0];
        [ProductPrinterView.layer setBorderColor:[[UIColor whiteColor] CGColor]];
        //AddvendorsView.layer.cornerRadius=8;
        [ProductPrinterPopUp addSubview:ProductPrinterView];
        
        CGFloat changeProductfieldwidth=(ProductPrinterView.frame.size.width)/2;
        
        if (!PrintTextlbl)
        PrintTextlbl=[[UILabel alloc] init];
        PrintTextlbl.frame=CGRectMake(changeProductfieldwidth-180, 10,changeProductfieldwidth, 30);
        [PrintTextlbl setFont:[UIFont systemFontOfSize:25.0f]];
        [PrintTextlbl setBackgroundColor:[UIColor clearColor]];
        [PrintTextlbl setTextColor:[UIColor whiteColor]];
        [PrintTextlbl setText:@"Send Printout to Department"];
        PrintTextlbl.lineBreakMode = NSLineBreakByWordWrapping;
        PrintTextlbl.numberOfLines = 2;
        [PrintTextlbl setTextAlignment:NSTextAlignmentLeft];
        [ProductPrinterView addSubview:PrintTextlbl];
        
        if (!ProductPrintertable)
        ProductPrintertable = [[UITableView alloc] initWithFrame:CGRectMake(10,60, ProductPrinterView.frame.size.width-20,ProductPrinterView.frame.size.height-300)];
        
        ProductPrintertable.backgroundColor=[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f];
        ProductPrintertable.delegate = self;
        ProductPrintertable.dataSource = self;
        ProductPrintertable.scrollEnabled = YES;
        [ProductPrinterView addSubview:ProductPrintertable];
        
        if (!SavePrintBtn)
        SavePrintBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        SavePrintBtn.frame=CGRectMake(changeProductfieldwidth-80,ProductPrinterView.frame.size.height-100 , 80, 30);
        [SavePrintBtn addTarget:self action:@selector(YESProductPrinterData) forControlEvents:UIControlEventTouchUpInside];
        
        [SavePrintBtn setTitle:@"YES" forState:UIControlStateNormal];
        [SavePrintBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [SavePrintBtn setBackgroundImage:[UIImage imageNamed:@"additionaloptionspressed.png"] forState:UIControlStateNormal];
        [ProductPrinterView addSubview:SavePrintBtn];
        if (!CancelPrintBtn)
        CancelPrintBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        CancelPrintBtn.frame=CGRectMake(changeProductfieldwidth+40, ProductPrinterView.frame.size.height-100 , 80, 30);
        [CancelPrintBtn addTarget:self action:@selector(NoProductPrinter) forControlEvents:UIControlEventTouchUpInside];
        [CancelPrintBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [CancelPrintBtn setBackgroundImage:[UIImage imageNamed:@"additionaloptionspressed.png"] forState:UIControlStateNormal];
        [CancelPrintBtn setTitle:@"NO" forState:UIControlStateNormal];
        [ProductPrinterView addSubview:CancelPrintBtn];
        
    }
    PrinterexistStr=nil;
}
-(void)NoProductPrinter
{
    [ProductNamesArray removeAllObjects],[DepPrinterDataArray removeAllObjects],[DepTimesArray removeAllObjects];
    ProductNamesArray=nil;
    DepPrinterDataArray=nil;
    DepTimesArray=nil;
    NSArray *ProductPrinterPopUpArray = ProductPrinterPopUp.subviews;
    for (int i = 0; i<[ProductPrinterPopUpArray count]; i++) {
        UIView *vi =[ProductPrinterPopUpArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *ProductPrinterViewArray = ProductPrinterView.subviews;
    for (int i = 0; i<[ProductPrinterViewArray count]; i++) {
        UIView *vi =[ProductPrinterViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [ProductPrinterView removeFromSuperview],[ProductPrinterPopUp removeFromSuperview];
}
-(void)YESProductPrinterData
{
   
    for (int i=0; i<[ProductNamesArray count]; i++)
    {
        //NSString *timestr;
        
        NSString *product=[ProductNamesArray objectAtIndex:i];
        NSString *time=[DepTimesArray objectAtIndex:i];
        NSString *printer=[DepPrinterDataArray objectAtIndex:i];
        NSString *mwssage=[QtyitemsArry objectAtIndex:i];

        int addTime=[time intValue];
        NSDate *today = [NSDate date];
        NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"HH:mm"];
      
        today=[today dateByAddingTimeInterval:addTime*60];
        NSString *dateOutPut=[formatter stringFromDate:today];
        
        NSString  *StoreSql=@"insert into printer_commands (department_printer,department_print_time,item_name,message,unique_id,created_timestamp,modified_timestamp,hold_id) values(?,?,?,?,?,?,?,?)";
        // //NSLog(@"store data %@",StoreSql);
     
        NSMutableArray *storeArray=[[NSMutableArray alloc]initWithObjects:printer,dateOutPut,product,mwssage,[generalDataObject  genRandStringLength:20],[generalDataObject getsystemDatetime],[generalDataObject getsystemDatetime],PrinterHoldID, nil];
        [[DataBaseManager dataBaseManager]executeRecordsWithQuery:StoreSql withArguments:storeArray];
        StoreSql=nil;
        product=nil,time=nil,printer=nil,mwssage=nil,formatter=nil;
        
    }
    
    [ProductNamesArray removeAllObjects],[DepPrinterDataArray removeAllObjects],[DepTimesArray removeAllObjects];
    ProductNamesArray=nil;
    DepPrinterDataArray=nil;
    DepTimesArray=nil;
    NSArray *ProductPrinterPopUpArray = ProductPrinterPopUp.subviews;
    for (int i = 0; i<[ProductPrinterPopUpArray count]; i++) {
        UIView *vi =[ProductPrinterPopUpArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *ProductPrinterViewArray = ProductPrinterView.subviews;
    for (int i = 0; i<[ProductPrinterViewArray count]; i++) {
        UIView *vi =[ProductPrinterViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [ProductPrinterView removeFromSuperview],[ProductPrinterPopUp removeFromSuperview];
    
     //[NSTimer scheduledTimerWithTimeInterval:25.0f target:self selector:@selector(SendDeptPrintMethod) userInfo:nil repeats:YES];
     //[self performSelector:@selector(SendDeptPrintMethod) withObject:nil afterDelay:25.0f];
   // [NSThread detachNewThreadSelector:@selector(SendDeptPrintMethod) toTarget: withObject:nil];
    
    
}
-(void)SendDeptPrintMethod
{
    
      NSString *querySQL = [NSString stringWithFormat: @"SELECT department_print_time,message,unique_id FROM printer_commands "];
    NSMutableArray *printersArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:printersArray];
    
    NSString *DBTime,*Message,*uniqueId;
    for (NSDictionary *myDict in printersArray)
    {
        DBTime=[myDict objectForKey:@"department_print_time"];
        //PrinterName=[myDict objectForKey:@"department_printer"];
        Message=[myDict objectForKey:@"message"];
        uniqueId=[myDict objectForKey:@"unique_id"];
        
        NSDate *today = [NSDate date];
        NSDateFormatter *datePickerFormat = [[NSDateFormatter alloc] init];
        [datePickerFormat setDateFormat:@"HH:mm"];
        NSString *dateOutPut=[datePickerFormat stringFromDate:today];
        NSDate *currentDate = [datePickerFormat dateFromString:dateOutPut];
        NSDate *serverDate = [datePickerFormat dateFromString:DBTime];
        dateOutPut=nil;
        //// //NSLog(@"date %@",currentDate);
       // // //NSLog(@"date %@",serverDate);
        
        NSComparisonResult result;
        
        result = [currentDate compare:serverDate]; // comparing two dates
        
        if(result == NSOrderedAscending)
           NSLog(@"current date is less");
        else if(result == NSOrderedDescending)
        {
              // //NSLog(@"server date is less");
           NSMutableString *stringToPrint = [[NSMutableString alloc] initWithString:@""];
           
            // //NSLog(@"Dept  Print data %@",stringToPrint);
            
            [stringToPrint appendFormat:@"<html><head><style type=\"text/css\">body {background-color:none;font-family : Verdana;color:#000000;font-size:28px;} table td {font-family : Verdana;color:#000000;font-size:28px; padding:0px 15px;} .tablehead{ font-size:32px;} </style><body style='background-color:none;'><center><table cellspacing=\"10\" width=';100%%' align='center' border=\"0\"><tr><th align=\"center\" colspan=\"2\">AonePOS</th></tr>"];
            
            
            
            [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Invoice#%@</span></th></tr>",[generalDataObject  getDeviceID]];
            [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Closed to Cash Purchase</span></th></tr>"];
             [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\"> DATE/TIME:%@</span></th></tr>",[generalDataObject getsystemDatetime]];
            
            [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\">CASHIER:1234</th></tr>"];
            [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"> STATION:1 </th></tr>"];
            [stringToPrint appendFormat:@"<tr><th align=\"left\" colspan=\"2\">Item :%@</th></tr>",Message];

              [stringToPrint appendFormat:@"</table></center></body></html>"];
         
             [self printImageMethod:&stringToPrint];
            
            NSString *updateSQL =@"DELETE FROM printer_commands WHERE unique_id=?";
            
            NSMutableArray *deleteArray=[[NSMutableArray alloc]initWithObjects:uniqueId, nil];
            [[DataBaseManager dataBaseManager]executeRecordsWithQuery:updateSQL withArguments:deleteArray];
            updateSQL=nil;
        }
        else if(result == NSOrderedSame)
        {
           // // //NSLog(@"Both dates are same");
            
            NSMutableString *stringToPrint = [[NSMutableString alloc] initWithString:@""];
            [stringToPrint appendFormat:@"<html><head><style type=\"text/css\">body {background-color:none;font-family : Verdana;color:#000000;font-size:28px;} table td {font-family : Verdana;color:#000000;font-size:28px; padding:0px 15px;} .tablehead{ font-size:32px;} </style><body style='background-color:none;'><center><table cellspacing=\"10\" width=';100%%' align='center' border=\"0\"><tr><th align=\"center\" colspan=\"2\">AonePOS</th></tr>"];
            
            
            
            [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Invoice#%@</span></th></tr>",[generalDataObject  getDeviceID]];
            [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Closed to Cash Purchase</span></th></tr>"];
            [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\"> DATE/TIME:%@</span></th></tr>",[generalDataObject getsystemDatetime]];
            
            [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\">CASHIER:1234</th></tr>"];
            [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"> STATION:1 </th></tr>"];
            [stringToPrint appendFormat:@"<tr><th align=\"left\" colspan=\"2\">Item :%@</th></tr>",Message];
            
            [stringToPrint appendFormat:@"</table></center></body></html>"];
            
            [self printImageMethod:&stringToPrint];
            
            NSString *updateSQL =@"DELETE FROM printer_commands WHERE unique_id=?";
            
            NSMutableArray *deleteArray=[[NSMutableArray alloc]initWithObjects:uniqueId, nil];
            [[DataBaseManager dataBaseManager]executeRecordsWithQuery:updateSQL withArguments:deleteArray];
            
        }
        else
            //NSLog(@"Date cannot be compared");
       
        
        datePickerFormat=nil;
    }
    DBTime=nil,Message=nil,uniqueId=nil;
    if ([PrinterIpsArray count]>0)
    {
        [self PrinterDataMethod];
        // [self GetPrint];
    }
    
}
-(void)FindCustomerClicked
{
    if (RecallinvoiceValue==YES)
    {
        [FindBtn removeTarget:nil
                         action:NULL
               forControlEvents:UIControlEventAllEvents];
    }
    else if (RecallinvoiceValue==NO)
    {
      NSString *querySQL = [NSString stringWithFormat: @"SELECT customer_no FROM customer_table"];
        NSMutableArray *custArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:custArray];
        
    if ([custArray count]>0)
    {
        if (!CustomerViewpopup)
        CustomerViewpopup=[[UIView alloc]init];
        if (isLandScope) {
            CustomerViewpopup.frame=CGRectMake(0, 0, 1024, 768);
        }
        
        else{
            
            CustomerViewpopup.frame=CGRectMake(0, 0, 768, 1024);
        }
        [CustomerViewpopup setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
        [self.view addSubview:CustomerViewpopup];
        
        if (!CustomerPastDataArray)
        CustomerPastDataArray=[[NSMutableArray alloc]init];
        if (!CustomerDataArray)
        CustomerDataArray=[[NSMutableArray alloc]init];
        
        NSString *querySQL = [NSString stringWithFormat: @"SELECT customer_no,customer_first_name FROM customer_table"];
        NSMutableArray *custArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:custArray];
        for (NSDictionary *myDict in custArray)
        {
            [CustomerPastDataArray addObject:[myDict objectForKey:@"customer_no"]];
            [CustomerPastDataArray addObject:[myDict objectForKey:@"customer_first_name"]];
        }
        if (!CustomerView)
        CustomerView=[[UIScrollView alloc]init];
        CustomerView.frame=CGRectMake(20, 40, CustomerViewpopup.frame.size.width-40, CustomerViewpopup.frame.size.height-80);
        CustomerView.contentSize=CGSizeMake(CustomerViewpopup.frame.size.width-40, CustomerViewpopup.frame.size.height+300);
        [CustomerView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
        [CustomerView.layer setBorderWidth:2.0];
        [CustomerView.layer setBorderColor:[[UIColor whiteColor] CGColor]];
        //AddvendorsView.layer.cornerRadius=8;
        [CustomerViewpopup addSubview:CustomerView];
        
        if (!CustomerlistTable)
        CustomerlistTable = [[UITableView alloc] initWithFrame:CGRectMake(0,0, CustomerView.frame.size.width,CustomerView.frame.size.height-100)];
        CustomerlistTable.backgroundColor=[UIColor whiteColor];
        CustomerlistTable.delegate = self;
        CustomerlistTable.dataSource = self;
        CustomerlistTable.scrollEnabled = YES;
        [CustomerView addSubview:CustomerlistTable];
        
        if (!CustomerSearchField)
        CustomerSearchField=[[UITextField alloc] init];
        CustomerSearchField.frame=CGRectMake(20,CustomerlistTable.frame.size.height+25,250, 40);
        // [SearchField addTarget:self action:@selector(AddressFieldClicked:) forControlEvents:UIControlEventEditingDidEnd];
        CustomerSearchField.delegate=self;
        UIView *paddingview10=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
        CustomerSearchField.leftView = paddingview10;
        CustomerSearchField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        CustomerSearchField.leftViewMode = UITextFieldViewModeAlways;
        [CustomerSearchField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
        [CustomerSearchField setAutocorrectionType:UITextAutocorrectionTypeNo];
        [CustomerView addSubview:CustomerSearchField];
        
        if (!CustomerDataTable)
        CustomerDataTable = [[UITableView alloc] initWithFrame:CGRectMake(20,CustomerlistTable.frame.size.height+25+40,250, 100) style:UITableViewStylePlain];
        CustomerDataTable.backgroundColor=[UIColor whiteColor];
        CustomerDataTable.delegate = self;
        CustomerDataTable.dataSource = self;
        CustomerDataTable.scrollEnabled = YES;
        CustomerDataTable.hidden=YES;
        [CustomerDataTable.layer setBorderWidth: 1.0];
        [CustomerDataTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
        [CustomerView addSubview:CustomerDataTable];
        
        if (!CustomerGobtn)
        CustomerGobtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        CustomerGobtn.frame=CGRectMake(CustomerSearchField.frame.size.width+30,CustomerlistTable.frame.size.height+25,40, 40);
        [CustomerGobtn addTarget:self action:@selector(CustomerGoBtnClicked) forControlEvents:UIControlEventTouchUpInside];
        [CustomerGobtn setTitle:@"Go" forState:UIControlStateNormal];
        [CustomerGobtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [CustomerGobtn setBackgroundImage:[UIImage imageNamed:@"okay-button.png"] forState:UIControlStateNormal];
        [CustomerView addSubview:CustomerGobtn];
        
        if (!CustomerCancelBtn)
        CustomerCancelBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        CustomerCancelBtn.frame=CGRectMake(CustomerSearchField.frame.size.width+30+CustomerGobtn.frame.size.width+10,CustomerlistTable.frame.size.height+25,100, 40);
        [CustomerCancelBtn addTarget:self action:@selector(CustomerCancelBtnClicked) forControlEvents:UIControlEventTouchUpInside];
        
        [CustomerCancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [CustomerCancelBtn setBackgroundImage:[UIImage imageNamed:@"cancelgreenbutton.png"] forState:UIControlStateNormal];
        [CustomerView addSubview:CustomerCancelBtn];
    
        [self GetcustomerDatamethod];
    }
 }
}
-(void) GetcustomerDatamethod
{
   
    CustomerNosArray=[[NSMutableArray alloc]init];
    CuFirstnamesArray=[[NSMutableArray alloc]init];
    CuLastnamesArray=[[NSMutableArray alloc]init];
    CuSnosArray=[[NSMutableArray alloc]init];
    
    
    //[CustomerNosArray addObject:@""];
    
    //[CuFirstnamesArray addObject:@""];
   
    //[CuLastnamesArray addObject:@""];
    
    NSString *querySQL = [NSString stringWithFormat: @"SELECT customer_no,customer_first_name,customer_last_name FROM customer_table"];
    NSMutableArray *custArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:custArray];
    @autoreleasepool {
        for (NSDictionary *myDict in custArray)
        {
            
            [CustomerNosArray addObject:[myDict objectForKey:@"customer_no"]];
            [CuFirstnamesArray addObject:[myDict objectForKey:@"customer_first_name"]];
            [CuLastnamesArray addObject:[myDict objectForKey:@"customer_last_name"]];
            [CuSnosArray addObject:[NSString stringWithFormat:@"%d",[CustomerNosArray count]]];
        }
    }
    
   
       ShCompanynamesArray=[[NSMutableArray alloc]init];
  
      ShPhonenumbersArray=[[NSMutableArray alloc]init];
    
    //[ShCompanynamesArray addObject:@""];
    //[ShPhonenumbersArray addObject:@""];
    
    
    NSString *querySQL2 = [NSString stringWithFormat: @"SELECT shipping_phone,shipping_company_name FROM customer_shipping_table"];
    NSMutableArray *custshpArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL2 resultsArray:custshpArray];
    @autoreleasepool {
        for (NSDictionary *myDict in custshpArray)
        {
            NSString *phno=[myDict objectForKey:@"shipping_phone"];
            if ([phno length]==0)
            {
                [ShPhonenumbersArray addObject:@""];
            }else{
                [ShPhonenumbersArray addObject:phno];
            }
            NSString *companyName=[myDict objectForKey:@"shipping_company_name"];
            if ([companyName length]==0)
            {
                [ShCompanynamesArray addObject:@""];
            }else{
                [ShCompanynamesArray addObject:companyName];
            }
            
        }
    }
    NSLog(@"%@",ShCompanynamesArray);

}
-(void)CustomerCancelBtnClicked
{
    [CustomerNosArray removeAllObjects],[CuFirstnamesArray removeAllObjects], [CuLastnamesArray removeAllObjects],[CuSnosArray removeAllObjects];
    
    CustomerNosArray=nil;
    CuFirstnamesArray=nil;
    CuLastnamesArray=nil;
    CuSnosArray=nil;
    [self customerViewRemovemethod];
    
}
-(void)MyswitchClicked2:(UISwitch *)sender
{
    if (sender.on ){
            
            [sender setOn:FALSE animated:YES];
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
            NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"switch.txt"];
            
            DeptSwitchValue = @"OFF";
            
            [DeptSwitchValue writeToFile:filePath atomically:TRUE encoding:NSUTF8StringEncoding error:NULL];
            NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
            NSString *documentsDirectory2 = [paths2 objectAtIndex:0];
            NSString *getImagePath = [documentsDirectory2 stringByAppendingPathComponent:@"switch.txt"];
            
            DeptSwitchValue = [NSString stringWithContentsOfFile:getImagePath encoding:NSUTF8StringEncoding error:nil];
            
            Swicthtextlbl.text=DeptSwitchValue;
            filePath=nil,documentsDirectory=nil,paths=nil;
        }else{
            
            [sender setOn:TRUE animated:YES];
            
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
            NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"switch.txt"];
            
            DeptSwitchValue = @"ON";
            
            [DeptSwitchValue writeToFile:filePath atomically:TRUE encoding:NSUTF8StringEncoding error:NULL];
            
            NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
            NSString *documentsDirectory2 = [paths2 objectAtIndex:0];
            NSString *getImagePath = [documentsDirectory2 stringByAppendingPathComponent:@"switch.txt"];
            
            DeptSwitchValue = [NSString stringWithContentsOfFile:getImagePath encoding:NSUTF8StringEncoding error:nil];
            
            Swicthtextlbl.text=DeptSwitchValue;
            filePath=nil,documentsDirectory=nil,paths=nil;
        }
    
}
-(void)PrinterswitchClicked:(UISwitch *)sender
{
    if (sender.on){
        
        [sender setOn:FALSE animated:YES];
        PrinterswitchValue=@"no";
        
    }else
    {
        PrinterswitchValue=@"yes";
        [sender setOn:TRUE animated:YES];
        
    }
    
}
-(void)MyswitchClicked:(UISwitch *)sender
{
    if (sender.on){
        [sender setOn:FALSE animated:YES];
       
    }else{
        
        [sender setOn:TRUE animated:YES];
       
    }
}
-(void)SearchBtnClicked
{
    
    if (RecallinvoiceValue==YES){
        [SearchBtn removeTarget:nil
                        action:NULL
              forControlEvents:UIControlEventAllEvents];
    }else  if (RecallinvoiceValue==NO)
    {
       
        NSString *querySQL = [NSString stringWithFormat:@"SELECT inventory_item_no,inventary_item_name FROM inventorytable"];
        NSMutableArray *productDataArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:productDataArray];
        querySQL=nil;
    if ([productDataArray count]>0)
    {
    if (!SearchViewpopup)
    SearchViewpopup=[[UIView alloc]init];
    if (isLandScope) {
        SearchViewpopup.frame=CGRectMake(0, 0, 1024, 768);
    }else{
        
        SearchViewpopup.frame=CGRectMake(0, 0, 768, 1024);
    }
    [SearchViewpopup setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:SearchViewpopup];
    
    if (!SearchView)
    SearchView=[[UIScrollView alloc]init];
    SearchView.frame=CGRectMake(20, 40, SearchViewpopup.frame.size.width-40, SearchViewpopup.frame.size.height-80);
    SearchView.contentSize=CGSizeMake(SearchViewpopup.frame.size.width-40, SearchViewpopup.frame.size.height+300);
    [SearchView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    [SearchView.layer setBorderWidth:2.0];
    [SearchView.layer setBorderColor:[[UIColor whiteColor] CGColor]];
    //AddvendorsView.layer.cornerRadius=8;
    [SearchViewpopup addSubview:SearchView];
        
    if (!SearchlistTable)
    SearchlistTable = [[UITableView alloc] initWithFrame:CGRectMake(0,0, SearchView.frame.size.width,SearchView.frame.size.height-100)];
    
    SearchlistTable.backgroundColor=[UIColor whiteColor];
    SearchlistTable.delegate = self;
    SearchlistTable.dataSource = self;
    SearchlistTable.scrollEnabled = YES;
    [SearchView addSubview:SearchlistTable];
    
    CGFloat SearchW=(SearchView.frame.size.width-20)/7;
   
    if (!Catlbl)
    Catlbl=[[UILabel alloc] init];
    Catlbl.frame=CGRectMake(10,SearchlistTable.frame.size.height+25,SearchW-15,40);
    [Catlbl setFont:[UIFont systemFontOfSize:20.0f]];
    [Catlbl setBackgroundColor:[UIColor clearColor]];
    [Catlbl setTextColor:[UIColor whiteColor]];
    [Catlbl setText:@"Category"];
    [Catlbl setTextAlignment:NSTextAlignmentLeft];
    [SearchView addSubview:Catlbl];
    
    if (!CatBtn)
    CatBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    CatBtn.frame=CGRectMake(Catlbl.frame.size.width+10,SearchlistTable.frame.size.height+25,SearchW+15,40);
    [CatBtn addTarget:self action:@selector(CategorySelectedBtn) forControlEvents:UIControlEventTouchUpInside];
    [CatBtn setTitle:@"All"  forState:UIControlStateNormal];
    [CatBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [CatBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    [SearchView addSubview:CatBtn];
    
    if (!Deptlbl)
    Deptlbl=[[UILabel alloc] init];
    Deptlbl.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+5,SearchlistTable.frame.size.height+25,SearchW+15, 40);
    [Deptlbl setFont:[UIFont systemFontOfSize:20.0f]];
    [Deptlbl setBackgroundColor:[UIColor clearColor]];
    [Deptlbl setTextColor:[UIColor whiteColor]];
    [Deptlbl setText:@"Department"];
    [Deptlbl setTextAlignment:NSTextAlignmentLeft];
    [SearchView addSubview:Deptlbl];
    
    if (!DeptBtn)
    DeptBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    DeptBtn.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+5,SearchlistTable.frame.size.height+25,SearchW+15, 40);
    [DeptBtn addTarget:self action:@selector(DepartmentSelectedBtn) forControlEvents:UIControlEventTouchUpInside];
    
    [DeptBtn setTitle:@"All" forState:UIControlStateNormal];
    
    [DeptBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [DeptBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    [SearchView addSubview:DeptBtn];
    
   
    if (!SearchField)
    SearchField=[[UITextField alloc] init];
    SearchField.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+DeptBtn.frame.size.width+15,SearchlistTable.frame.size.height+25,SearchW+15, 40);
   // [SearchField addTarget:self action:@selector(AddressFieldClicked:) forControlEvents:UIControlEventEditingDidEnd];
    SearchField.delegate=self;
    UIView *paddingview10=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    SearchField.leftView = paddingview10;
    SearchField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    SearchField.leftViewMode = UITextFieldViewModeAlways;
    [SearchField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
    [SearchField setAutocorrectionType:UITextAutocorrectionTypeNo];
    [SearchView addSubview:SearchField];
        [paddingview10 removeFromSuperview];
        paddingview10=nil;
    if (!ItemsDataTable)
    ItemsDataTable = [[UITableView alloc] initWithFrame:CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+DeptBtn.frame.size.width+15,SearchlistTable.frame.size.height+25+40,SearchW+15, 100) style:UITableViewStylePlain];
    ItemsDataTable.backgroundColor=[UIColor whiteColor];
    ItemsDataTable.delegate = self;
    ItemsDataTable.dataSource = self;
    ItemsDataTable.scrollEnabled = YES;
    ItemsDataTable.hidden=YES;
    [ItemsDataTable.layer setBorderWidth: 1.0];
    [ItemsDataTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [SearchView addSubview:ItemsDataTable];
    
        @autoreleasepool {
            Gobtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            
            Gobtn.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+DeptBtn.frame.size.width+SearchField.frame.size.width+20,SearchlistTable.frame.size.height+25,40, 40);
            [Gobtn addTarget:self action:@selector(GoBtnClicked) forControlEvents:UIControlEventTouchUpInside];
            
            [Gobtn setTitle:@"Go" forState:UIControlStateNormal];
            [Gobtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [Gobtn setBackgroundImage:[UIImage imageNamed:@"okay-button.png"] forState:UIControlStateNormal];
            [SearchView addSubview:Gobtn];
            
            CancelItemBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            
            CancelItemBtn.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+DeptBtn.frame.size.width+SearchField.frame.size.width+Gobtn.frame.size.width+25,SearchlistTable.frame.size.height+25,SearchW, 40);
            [CancelItemBtn addTarget:self action:@selector(CancelBtnClicked) forControlEvents:UIControlEventTouchUpInside];
            
            [CancelItemBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [CancelItemBtn setBackgroundImage:[UIImage imageNamed:@"cancelgreenbutton.png"] forState:UIControlStateNormal];
            [SearchView addSubview:CancelItemBtn];

        }
        [self getsearchlistDataMethod];
    
        if (!pastDataArray)
        pastDataArray=[[NSMutableArray alloc]init];
         if (!SearchDataArray)
        SearchDataArray=[[NSMutableArray alloc]init];
        @autoreleasepool {
            for (NSDictionary *myDict in productDataArray)
            {
                [pastDataArray addObject:[myDict objectForKey:@"inventory_item_no"]];
                [pastDataArray addObject:[myDict objectForKey:@"inventary_item_name"]];
                
            }
        }
      
        
    }
 }
}
-(void) getsearchlistDataMethod
{
    
    NSString *querySQL = [NSString stringWithFormat:@"SELECT inventory_item_no,inventary_item_name,inventary_second_description,inventary_price_change,inventary_in_stock FROM inventorytable"];
    NSMutableArray *productDataArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:productDataArray];
   
    ItemNumbersArray=[[NSMutableArray alloc]init];
     ItemnameArray=[[NSMutableArray alloc]init];
    productDesArray=[[NSMutableArray alloc]init];
    SnosArray=[[NSMutableArray alloc]init];
    priceyouchargeArray=[[NSMutableArray alloc]init];
    InstockArray=[[NSMutableArray alloc]init];
    [ItemnameArray addObject:@""];
    [ItemNumbersArray addObject:@""];
    [productDesArray addObject:@""];
    [priceyouchargeArray addObject:@""];
    [InstockArray addObject:@""];
    [SnosArray addObject:@""];
    
    @autoreleasepool {
        for (NSDictionary *myDict in productDataArray)
        {
            
             [ItemNumbersArray addObject:[myDict objectForKey:@"inventory_item_no"]];
            
            [ItemnameArray addObject:[myDict objectForKey:@"inventary_item_name"]];
            [productDesArray addObject:[myDict objectForKey:@"inventary_second_description"]];
            
            [priceyouchargeArray addObject:[myDict objectForKey:@"inventary_price_change"]];
            
            [InstockArray addObject:[myDict objectForKey:@"inventary_in_stock"]];
        
        }
    }
   
    for (int i=1;i<=[ItemNumbersArray count] ; i++)
    {
        [SnosArray  addObject:[NSString stringWithFormat:@"%d",i]];
        
    }
    
    
  
    VendorpartNosArray=[[NSMutableArray alloc]init];
    NSString *querySQL2;
    
    if ([ItemNumbersArray count]>0){
        
        for (int i=0; i<[ItemNumbersArray count]; i++)
        {
            NSString *ProductNumber=[ItemNumbersArray objectAtIndex:i];
            querySQL2 = [NSString stringWithFormat: @"SELECT venderpart_no FROM ordering_info_table WHERE inventory_item_no='%@' AND preferred='%@'",ProductNumber,@"True"];
            
            NSMutableArray *vendorArray=[[NSMutableArray alloc]init];
            [[DataBaseManager dataBaseManager]execute:querySQL2 resultsArray:vendorArray];
            
            if ([vendorArray count]>0)
            {    NSDictionary *dict=[vendorArray objectAtIndex:0];
                [VendorpartNosArray addObject:[dict objectForKey:@"venderpart_no"]];
            }
            else
            {
                [VendorpartNosArray addObject:@""];
            }
        }
        
    }

}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    
    if(textField == SearchField){
        ItemsDataTable.hidden = NO;
        NSString *substring = [NSString stringWithString:textField.text];
        substring = [substring stringByReplacingCharactersInRange:range withString:string];
        [self searchAutocompleteEntriesWithSubstring:substring];
        substring=nil;
    } else if(textField == CustomerSearchField) {
          //[self GetcustomerDatamethod];
        CustomerDataTable.hidden = NO;
        NSString *substring = [NSString stringWithString:textField.text];
        substring = [substring stringByReplacingCharactersInRange:range withString:string];
        [self searchAutocompleteEntriesWithSubstring2:substring];
        substring=nil;
    }
    return YES;
    
}
- (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring {
    
    // Put anything that starts with this substring into the autocompleteUrls array
    // The items in this array is what will show up in the table view
    if ([substring length]>=2){
        
        
        [SearchDataArray removeAllObjects];
        SearchDataArray=nil;
        for(NSMutableString *curString in pastDataArray)
        {
            NSRange titleResultsRange = [curString rangeOfString:substring options:NSCaseInsensitiveSearch];
            
            if (titleResultsRange.length > 0)
                [SearchDataArray addObject:curString];
            
        }
        
        [ItemsDataTable reloadData];
        
    }else{
        ItemsDataTable.hidden=YES;
    }
}

- (void)searchAutocompleteEntriesWithSubstring2:(NSString *)substring2
{
    
    // Put anything that starts with this substring into the autocompleteUrls array
    // The items in this array is what will show up in the table view
    if ([substring2 length]>=2){
        
        [CustomerDataArray removeAllObjects];
        CustomerDataArray=nil;
        for(NSMutableString *curString in CustomerPastDataArray)
        {
            NSRange titleResultsRange = [curString rangeOfString:substring2 options:NSCaseInsensitiveSearch];
            
            if (titleResultsRange.length > 0)
                [CustomerDataArray addObject:curString];
            
        }
          //[self GetcustomerDatamethod];
        [CustomerDataTable reloadData];
       
        
    }else{
        CustomerDataTable.hidden=YES;
    }
}
-(void)PriceChangeClciked
{
    
    if (RecallinvoiceValue==YES)
    {
        [PriceChangeBtn removeTarget:nil
                           action:NULL
                 forControlEvents:UIControlEventAllEvents];
    }
    else if (RecallinvoiceValue==NO)
    {
    if ([[generalDataObject  userType] isEqualToString:@"employee"])
    {
        if ([[generalDataObject  invoice_price_change_permission] isEqualToString:@"yes"])
        {
            if (itemselected)
            {
                if (!PricePopupView)
                PricePopupView=[[UIView alloc]init];
                if (isLandScope) {
                    PricePopupView.frame=CGRectMake(0, 0, 1024, 768);
                }
                
                else{
                    
                    PricePopupView.frame=CGRectMake(0, 0, 768, 1024);
                }
                [PricePopupView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
                [self.view addSubview:PricePopupView];
                
                 if (!Priceview)
                Priceview=[[UIScrollView alloc]init];
                if (isLandScope)
                {
                    Priceview.frame=CGRectMake(200, 200, PricePopupView.frame.size.width-400, PricePopupView.frame.size.height-450);
                }
                else
                {
                    Priceview.frame=CGRectMake(150, 300, PricePopupView.frame.size.width-300, PricePopupView.frame.size.height-750);
                }
                
                [Priceview setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
                
                [Priceview.layer setBorderWidth:2.0];
                [Priceview.layer setBorderColor:[[UIColor whiteColor] CGColor]];
                //AddvendorsView.layer.cornerRadius=8;
                [PricePopupView addSubview:Priceview];
                
                
                CGFloat Pricewidth=(Priceview.frame.size.width)/2;
                CGFloat pricew=Pricewidth/2;
                if (!PriceTextlbl)
                PriceTextlbl=[[UILabel alloc] init];
                PriceTextlbl.frame=CGRectMake(pricew-60, 25,Pricewidth, 50);
                [PriceTextlbl setFont:[UIFont systemFontOfSize:25.0f]];
                [PriceTextlbl setBackgroundColor:[UIColor clearColor]];
                [PriceTextlbl setTextColor:[UIColor whiteColor]];
                [PriceTextlbl setText:@"Enter Price"];
                PriceTextlbl.lineBreakMode = NSLineBreakByWordWrapping;
                PriceTextlbl.numberOfLines = 2;
                [PriceTextlbl setTextAlignment:NSTextAlignmentLeft];
                [Priceview addSubview:PriceTextlbl];
                 if (!ChangePriceField)
                ChangePriceField=[[UITextField alloc] init];
                //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
                ChangePriceField.frame=CGRectMake(pricew-20, 95,Pricewidth+50, 40);
                ChangePriceField.delegate=self;
                
                UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
                // // //NSLog(@"%f",GeneralinfoField.frame.origin.y);
                ChangePriceField.leftView = paddingview;
                ChangePriceField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
                ChangePriceField.leftViewMode = UITextFieldViewModeAlways;
                [ChangePriceField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
                [ChangePriceField setAutocorrectionType:UITextAutocorrectionTypeNo];
                [Priceview addSubview:ChangePriceField];
                [paddingview removeFromSuperview];
                paddingview=nil;
                
                @autoreleasepool {
                    SavePriceBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                    
                    SavePriceBtn.frame=CGRectMake(Pricewidth-90, 180, 80, 30);
                    [SavePriceBtn addTarget:self action:@selector(SaveChangePrice) forControlEvents:UIControlEventTouchUpInside];
                    
                    //[SaveTaxButton setTitle:@"Save" forState:UIControlStateNormal];
                    [SavePriceBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [SavePriceBtn setBackgroundImage:[UIImage imageNamed:@"savegreenbutton.png"] forState:UIControlStateNormal];
                    [Priceview addSubview:SavePriceBtn];
                    
                    CancelPriceBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                    
                    CancelPriceBtn.frame=CGRectMake(Pricewidth+40, 180, 80, 30);
                    [CancelPriceBtn addTarget:self action:@selector(CancelChangePrice) forControlEvents:UIControlEventTouchUpInside];
                    [CancelPriceBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [CancelPriceBtn setBackgroundImage:[UIImage imageNamed:@"cancelgreenbutton.png"] forState:UIControlStateNormal];
                    // [CancelTaxButton setTitle:@"Cancel" forState:UIControlStateNormal];
                    [Priceview addSubview:CancelPriceBtn];
                }
              
                
            }else{
              
                [self.view makeToast:@"SelectItem"];
            }
            
        }
        else
        {
            UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
            
            [authalert show];
            authalert=nil;
        }
    }else{
      if (itemselected){
        // //NSLog(@"%d",indexNO);
        
        
        if (!PricePopupView)
            PricePopupView=[[UIView alloc]init];
        if (isLandScope) {
            PricePopupView.frame=CGRectMake(0, 0, 1024, 768);
        }else{
            
            PricePopupView.frame=CGRectMake(0, 0, 768, 1024);
        }
        [PricePopupView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
        [self.view addSubview:PricePopupView];
        
        if (!Priceview)
            Priceview=[[UIScrollView alloc]init];
        if (isLandScope){
            Priceview.frame=CGRectMake(200, 200, PricePopupView.frame.size.width-400, PricePopupView.frame.size.height-450);
        } else{
            Priceview.frame=CGRectMake(150, 300, PricePopupView.frame.size.width-300, PricePopupView.frame.size.height-750);
        }
        
        [Priceview setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
        
        [Priceview.layer setBorderWidth:2.0];
        [Priceview.layer setBorderColor:[[UIColor whiteColor] CGColor]];
        //AddvendorsView.layer.cornerRadius=8;
        [PricePopupView addSubview:Priceview];
        
        
        CGFloat Pricewidth=(Priceview.frame.size.width)/2;
        CGFloat pricew=Pricewidth/2;
        if (!PriceTextlbl)
        PriceTextlbl=[[UILabel alloc] init];
        PriceTextlbl.frame=CGRectMake(pricew-60, 25,Pricewidth, 50);
        [PriceTextlbl setFont:[UIFont systemFontOfSize:25.0f]];
        [PriceTextlbl setBackgroundColor:[UIColor clearColor]];
        [PriceTextlbl setTextColor:[UIColor whiteColor]];
        [PriceTextlbl setText:@"Enter Price"];
        PriceTextlbl.lineBreakMode = NSLineBreakByWordWrapping;
        PriceTextlbl.numberOfLines = 2;
        [PriceTextlbl setTextAlignment:NSTextAlignmentLeft];
        [Priceview addSubview:PriceTextlbl];
        if (!ChangePriceField)
            ChangePriceField=[[UITextField alloc] init];
        //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
        ChangePriceField.frame=CGRectMake(pricew-20, 95,Pricewidth+50, 40);
        ChangePriceField.delegate=self;
        
        UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
        // // //NSLog(@"%f",GeneralinfoField.frame.origin.y);
        ChangePriceField.leftView = paddingview;
        ChangePriceField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        ChangePriceField.leftViewMode = UITextFieldViewModeAlways;
        [ChangePriceField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
        [ChangePriceField setAutocorrectionType:UITextAutocorrectionTypeNo];
        [Priceview addSubview:ChangePriceField];
        [paddingview removeFromSuperview];
        paddingview=nil;
        
        @autoreleasepool {
            SavePriceBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            
            SavePriceBtn.frame=CGRectMake(Pricewidth-90, 180, 80, 30);
            [SavePriceBtn addTarget:self action:@selector(SaveChangePrice) forControlEvents:UIControlEventTouchUpInside];
            
            //[SaveTaxButton setTitle:@"Save" forState:UIControlStateNormal];
            [SavePriceBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [SavePriceBtn setBackgroundImage:[UIImage imageNamed:@"savegreenbutton.png"] forState:UIControlStateNormal];
            [Priceview addSubview:SavePriceBtn];
            
            CancelPriceBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            
            CancelPriceBtn.frame=CGRectMake(Pricewidth+40, 180, 80, 30);
            [CancelPriceBtn addTarget:self action:@selector(CancelChangePrice) forControlEvents:UIControlEventTouchUpInside];
            [CancelPriceBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [CancelPriceBtn setBackgroundImage:[UIImage imageNamed:@"cancelgreenbutton.png"] forState:UIControlStateNormal];
            // [CancelTaxButton setTitle:@"Cancel" forState:UIControlStateNormal];
            [Priceview addSubview:CancelPriceBtn];
        }

    }else{
        [self.view makeToast:@"SelectItem"];
        
    }
 }
}
}
-(void)discountViewremoveMethod
{
    NSArray *DiscountPopupViewArray = DiscountPopupView.subviews;
    for (int i = 0; i<[DiscountPopupViewArray count]; i++) {
        UIView *vi =[DiscountPopupViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *DiscountviewArray = Discountview.subviews;
    for (int i = 0; i<[DiscountviewArray count]; i++) {
        UIView *vi =[DiscountviewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [Discountview removeFromSuperview],[DiscountPopupView removeFromSuperview];
    DiscountPopupView=nil;
}
-(void)qtyViewremoveMethod
{
    NSArray *QuantityPopupViewArray = QuantityPopupView.subviews;
    for (int i = 0; i<[QuantityPopupViewArray count]; i++) {
        UIView *vi =[QuantityPopupViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *QuantityviewArray = Quantityview.subviews;
    for (int i = 0; i<[QuantityviewArray count]; i++) {
        UIView *vi =[QuantityviewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [Quantityview removeFromSuperview],[QuantityPopupView removeFromSuperview];
    QuantityPopupView=nil,Quantityview=nil;
}
-(void) PriceviewremoveMethod
{
    NSArray *PricePopupViewArray = PricePopupView.subviews;
    for (int i = 0; i<[PricePopupViewArray count]; i++) {
        UIView *vi =[PricePopupViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *PriceviewArray = Priceview.subviews;
    for (int i = 0; i<[PriceviewArray count]; i++) {
        UIView *vi =[PriceviewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [Priceview removeFromSuperview],[PricePopupView removeFromSuperview];
    PricePopupView=nil;
}

-(void)SaveChangePrice
{
    
    [self PriceviewremoveMethod];
    
    if ([ChangePriceField .text length]>0){
        
        [pricesArray removeObjectAtIndex:indexNO];
        [pricesArray insertObject:ChangePriceField.text atIndex:indexNO];
         [self GetTotalAmountMethod];
        [ProductslistTable reloadData];
        
    }else{
        UIAlertView *itemalert=[[UIAlertView alloc]initWithTitle:@"Alert" message:@"Enter Price" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
        
        [itemalert show];
        itemalert=nil;
    }
     itemselected=NO;
    
}
-(void)DiscountViewMethod
{
    if (!DiscountPopupView)
    DiscountPopupView=[[UIView alloc]init];
    if (isLandScope) {
        DiscountPopupView.frame=CGRectMake(0, 0, 1024, 768);
    }
    
    else{
        
        DiscountPopupView.frame=CGRectMake(0, 0, 768, 1024);
    }
    [DiscountPopupView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:DiscountPopupView];
    if (!Discountview)
    Discountview=[[UIScrollView alloc]init];
    if (isLandScope)
    {
        Discountview.frame=CGRectMake(200, 200, DiscountPopupView.frame.size.width-400, DiscountPopupView.frame.size.height-450);
    }
    else
    {
        Discountview.frame=CGRectMake(150, 300, DiscountPopupView.frame.size.width-300, DiscountPopupView.frame.size.height-750);
    }
    
    [Discountview setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    //[Discountview setBackgroundColor:[UIColor blackColor]];
    
    [Discountview.layer setBorderWidth:2.0];
    [Discountview.layer setBorderColor:[[UIColor whiteColor] CGColor]];
    //AddvendorsView.layer.cornerRadius=8;
    [DiscountPopupView addSubview:Discountview];
    
    
    CGFloat Diswidth=(Discountview.frame.size.width)/2;
    CGFloat dis=Diswidth/2;
     if (!DiscountTextlbl)
    DiscountTextlbl=[[UILabel alloc] init];
    DiscountTextlbl.frame=CGRectMake(dis-60, 25,Diswidth, 50);
    
    [DiscountTextlbl setFont:[UIFont systemFontOfSize:25.0f]];
    [DiscountTextlbl setBackgroundColor:[UIColor clearColor]];
    [DiscountTextlbl setTextColor:[UIColor whiteColor]];
    [DiscountTextlbl setText:@"Enter Discount %"];
    DiscountTextlbl.lineBreakMode = NSLineBreakByWordWrapping;
    DiscountTextlbl.numberOfLines = 2;
    [DiscountTextlbl setTextAlignment:NSTextAlignmentLeft];
    [Discountview addSubview:DiscountTextlbl];
       if (!ChangeDiscountField)
    ChangeDiscountField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    ChangeDiscountField.frame=CGRectMake(10, 95,Diswidth+50, 40);
    ChangeDiscountField.delegate=self;
    
    UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    // // //NSLog(@"%f",GeneralinfoField.frame.origin.y);
    ChangeDiscountField.leftView = paddingview;
    ChangeDiscountField.keyboardType=UIKeyboardTypeNumberPad;
    ChangeDiscountField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    ChangeDiscountField.leftViewMode = UITextFieldViewModeAlways;
    [ChangeDiscountField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
    [ChangeDiscountField setAutocorrectionType:UITextAutocorrectionTypeNo];
    [Discountview addSubview:ChangeDiscountField];
    [paddingview removeFromSuperview],paddingview=nil;
     if (!DisDropdownBtn)
    DisDropdownBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    DisDropdownBtn.frame=CGRectMake(ChangeDiscountField.frame.size.width+20, 95,150, 40);
    [DisDropdownBtn addTarget:self action:@selector(DisDropClicked) forControlEvents:UIControlEventTouchUpInside];
    [DisDropdownBtn setTitle:@"%" forState:UIControlStateNormal];
    [DisDropdownBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [DisDropdownBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    // [CancelTaxButton setTitle:@"Cancel" forState:UIControlStateNormal];
    DisDropdownBtn.hidden=YES;
    [Discountview addSubview:DisDropdownBtn];
     if (!DisTableview)
    DisTableview = [[UITableView alloc] initWithFrame:CGRectMake(ChangeDiscountField.frame.size.width+20, 135, 150, 80) style:UITableViewStylePlain];
    DisTableview.backgroundColor=[UIColor whiteColor];
    DisTableview.delegate = self;
    DisTableview.dataSource = self;
    DisTableview.scrollEnabled = YES;
    DisTableview.hidden=YES;
    [DisTableview.layer setBorderWidth: 1.0];
    [DisTableview.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [Discountview addSubview:DisTableview];
      if (!DisCheckBtn)
    DisCheckBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    DisCheckBtn.frame=CGRectMake(30,140,40, 40);
    
    [DisCheckBtn addTarget:self action:@selector(DischeckClicked) forControlEvents:UIControlEventTouchUpInside];
    [DisCheckBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [DisCheckBtn setBackgroundImage:[UIImage imageNamed:@"checkbox-off.png"] forState:UIControlStateNormal];
    [DisCheckBtn setBackgroundImage:[UIImage imageNamed:@"checkbox-on.png"] forState:UIControlStateSelected];
    [Discountview addSubview:DisCheckBtn];
    if (!OverAllDislbl)
    OverAllDislbl=[[UILabel alloc] init];
    OverAllDislbl.frame=CGRectMake(80, 140,Diswidth, 40);
    
    [OverAllDislbl setFont:[UIFont systemFontOfSize:25.0f]];
    [OverAllDislbl setBackgroundColor:[UIColor clearColor]];
    [OverAllDislbl setTextColor:[UIColor whiteColor]];
    [OverAllDislbl setText:@"OverAll Discount"];
    OverAllDislbl.lineBreakMode = NSLineBreakByWordWrapping;
    OverAllDislbl.numberOfLines = 2;
    [OverAllDislbl setTextAlignment:NSTextAlignmentLeft];
    [Discountview addSubview:OverAllDislbl];
    @autoreleasepool {
        SaveDiscountBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        SaveDiscountBtn.frame=CGRectMake(Diswidth-90, 220, 80, 30);
        [SaveDiscountBtn addTarget:self action:@selector(SaveChangeDiscount) forControlEvents:UIControlEventTouchUpInside];
        
        //[SaveTaxButton setTitle:@"Save" forState:UIControlStateNormal];
        [SaveDiscountBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [SaveDiscountBtn setBackgroundImage:[UIImage imageNamed:@"savegreenbutton.png"] forState:UIControlStateNormal];
        [Discountview addSubview:SaveDiscountBtn];
        
        CancelDiscountBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        CancelDiscountBtn.frame=CGRectMake(Diswidth+40, 220, 80, 30);
        [CancelDiscountBtn addTarget:self action:@selector(CancelChangeDiscount) forControlEvents:UIControlEventTouchUpInside];
        [CancelDiscountBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [CancelDiscountBtn setBackgroundImage:[UIImage imageNamed:@"cancelgreenbutton.png"] forState:UIControlStateNormal];
        // [CancelTaxButton setTitle:@"Cancel" forState:UIControlStateNormal];
        [Discountview addSubview:CancelDiscountBtn];
        if (!DiscsArray)
        DiscsArray=[[NSMutableArray alloc]initWithObjects:@"%",@"$", nil];
    }
  
}
-(void)CancelChangePrice
{
     [self PriceviewremoveMethod];
}
-(void)ChangeDiscountClicked
{
    if (RecallinvoiceValue==YES)
    {
        [DiscountBtn removeTarget:nil
                     action:NULL
           forControlEvents:UIControlEventAllEvents];
    }
else if (RecallinvoiceValue==NO)
{
    if ([[generalDataObject  userType] isEqualToString:@"employee"]){
        if ([[generalDataObject  invoice_discounts_permission] isEqualToString:@"yes"]){
            if (itemselected){
                [self DiscountViewMethod];
            }else{
                [self.view makeToast:@"SelectItem"];
            }
            
        }else{
            UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
            
            [authalert show];
            authalert=nil;
        }
    }
else{
    if (itemselected){
               [self DiscountViewMethod];
        
    }else{
            [self.view makeToast:@"SelectItem"];
    }
    }
 }
}
-(void)DisDropClicked
{
    if (DisTableview.hidden==1){
        
        DisTableview.hidden=NO;
        
        //IDfield.hidden=YES;
    }else if (DisTableview.hidden==0){
        [DisTableview setHidden:YES];
        //IDfield.hidden=NO;
        
    }
}
-(void)DischeckClicked
{
    if (DisCheckBtn.selected){
        [DisCheckBtn setSelected:NO];
        
        DisDropdownBtn.hidden=YES;
       //Deptfoodstampable=@"no";
    }else if(!DisCheckBtn.selected){
        [DisCheckBtn setSelected:YES];
           DisDropdownBtn.hidden=NO;
       // Deptfoodstampable=@"yes";
    }
    
}
-(void)SaveChangeDiscount
{
    [self discountViewremoveMethod];
    double pricevalue;
    NSString *tax;
    NSString *price;
    NSString *aveg;
    if (DisCheckBtn.selected){
        NSString *distype=[NSString stringWithFormat:@"%@",DisDropdownBtn.titleLabel.text];
        
        if ([distype isEqualToString:@"$"]){
              NSString *name=[ItemNamesArray objectAtIndex:0];
             [ItemNamesArray removeObjectAtIndex:0];
               [ItemNamesArray insertObject:[NSString stringWithFormat:@"%@%@%@%@",@"OverAllDis ",ChangeDiscountField.text,@"$",name] atIndex:0];
            
            double cprice=[ChangeDiscountField.text doubleValue];
             SubtotalValue=SubtotalValue-cprice;
            Grandvalue=Grandvalue-cprice;
            
            SubTotalstr = [NSString stringWithFormat:@"%@%.02f",@"$ ", SubtotalValue];
           // TaxValueStr = [NSString stringWithFormat:@"%.02f", TaxValue];
            GrandTotalstr=[NSString stringWithFormat:@"%@%.02f",@"$ ",Grandvalue];
            taxDlbl.text=TaxValueStr;
            SubTDisplaylbl.text=SubTotalstr;
            GTotalDlbl.text=GrandTotalstr;
            
            [ProductslistTable reloadData];
            name=nil;
            
        }else if ([distype isEqualToString:@"%"]){
            
              int count=0;
            NSString *myitemname;
            for (int i=0; i<[pricesArray count]; i++)
            {
               
                 NSString *itemno=[ItemNosArray objectAtIndex:i];
                NSString *querySQL = [NSString stringWithFormat:@"SELECT inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor FROM inventorytable"];
                NSMutableArray *productDataArray=[[NSMutableArray alloc]init];
                [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:productDataArray];
                
                for (NSDictionary *myDict in productDataArray)
                {
                    NSString *itemstr=[myDict objectForKey:@"inventory_item_no"];
                    if ([itemstr isEqualToString:itemno]){
                        myitemname=[myDict objectForKey:@"inventary_item_name"];
                
                    }
                    itemstr=nil;
                }
                    aveg=[AvegCostsArray objectAtIndex:i];
                    NSString *name=[ItemNamesArray objectAtIndex:i];
                
                if ([name rangeOfString:@"Discount"].location == NSNotFound){
                    //// //NSLog(@"string does not contain bla");
                }else {
                   // // //NSLog(@"string contains bla!");
                    name=myitemname;
                }
                    [DiscountsArray removeObjectAtIndex:i];
                    
                    [DiscountsArray insertObject:[NSString stringWithFormat:@"%@",ChangeDiscountField.text] atIndex:i];
                    
                    [ItemNamesArray removeObjectAtIndex:i];
                    
                    [ItemNamesArray insertObject:[NSString stringWithFormat:@"%@%@%@%@",name,@"Discount ",ChangeDiscountField.text,@"%"] atIndex:i];
                    
                    NSString *price=[pricesArray objectAtIndex:i];
                    double cprice=[price doubleValue]-(([price doubleValue]*[ChangeDiscountField.text doubleValue])/100);
                    [pricesArray removeObjectAtIndex:i];
                    
                    [pricesArray insertObject:[NSString stringWithFormat:@"%.02f",cprice] atIndex:i];
                    
                    tax=[TaxesArray objectAtIndex:i];
                    
                    pricevalue=cprice;
                    count=count+1;
                if (count>1){
                    SubtotalValue=SubtotalValue+pricevalue;
                    TaxValue=TaxValue+(([tax doubleValue]*pricevalue)/100);
                    Grandvalue=SubtotalValue+TaxValue;
                    TotalAvegCost=TotalAvegCost+[aveg doubleValue];
                }else{
                    SubtotalValue=pricevalue;
                    TaxValue=(([tax doubleValue]*pricevalue)/100);
                    Grandvalue=SubtotalValue+TaxValue;
                    TotalAvegCost=[aveg doubleValue];
                }
                itemno=nil;
            }
            SubTotalstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",SubtotalValue];
            TaxValueStr = [NSString stringWithFormat:@"%@%.02f", @"$ ",TaxValue];
            GrandTotalstr=[NSString stringWithFormat:@"%@%.02f", @"$ ",Grandvalue];
            
            taxDlbl.text=TaxValueStr;
            SubTDisplaylbl.text=SubTotalstr;
            GTotalDlbl.text=GrandTotalstr;
            
            [ProductslistTable reloadData];
            myitemname=nil;
        }
    
        distype=nil;
    }else{
    if ([ChangeDiscountField .text length]>0){
        int count=0;
            for (int i=0; i<[pricesArray count]; i++)
            {
                if (indexNO==i){
                     NSString *myitemname;
                    
                    NSString *itemno=[ItemNosArray objectAtIndex:i];
                    NSString *querySQL = [NSString stringWithFormat:@"SELECT inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor FROM inventorytable"];
                    NSMutableArray *productDataArray=[[NSMutableArray alloc]init];
                    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:productDataArray];
                    
                    for (NSDictionary *myDict in productDataArray)
                    {
                        NSString *itemstr=[myDict objectForKey:@"inventory_item_no"];
                        if ([itemstr isEqualToString:itemno]){
                            myitemname=[myDict objectForKey:@"inventary_item_name"];
                            
                        }
                        itemstr=nil;
                    }
                      aveg=[AvegCostsArray objectAtIndex:i];
                    NSString *name=[ItemNamesArray objectAtIndex:indexNO];
                    
                    if ([name rangeOfString:@"Discount"].location == NSNotFound){
                        //// //NSLog(@"string does not contain bla");
                    }else{
                       // // //NSLog(@"string contains bla!");
                        name=myitemname;
                    }
                    
                    [DiscountsArray removeObjectAtIndex:indexNO];
                    [DiscountsArray insertObject:[NSString stringWithFormat:@"%@",ChangeDiscountField.text] atIndex:indexNO];
                    [ItemNamesArray removeObjectAtIndex:indexNO];
                    [ItemNamesArray insertObject:[NSString stringWithFormat:@"%@%@%@%@",name,@"Discount ",ChangeDiscountField.text,@"%"] atIndex:indexNO];
                    
                    NSString *price=[pricesArray objectAtIndex:indexNO];
                    double cprice=[price doubleValue]-(([price doubleValue]*[ChangeDiscountField.text doubleValue])/100);
                    [pricesArray removeObjectAtIndex:indexNO];
                    [pricesArray insertObject:[NSString stringWithFormat:@"%.02f",cprice] atIndex:indexNO];
                    
                   tax=[TaxesArray objectAtIndex:indexNO];
                    pricevalue=cprice;

                   myitemname=nil,itemno=nil;;
                }else{
                     aveg=[AvegCostsArray objectAtIndex:i];
                   price=[pricesArray objectAtIndex:i];
                    tax=[TaxesArray objectAtIndex:i];
                    //// //NSLog(@"%@",price);
                    
                     pricevalue=[price doubleValue];
                }
                                count=count+1;
                if (count>1){
                    SubtotalValue=SubtotalValue+pricevalue;
                    TaxValue=TaxValue+(([tax doubleValue]*pricevalue)/100);
                    Grandvalue=SubtotalValue+TaxValue;
                    TotalAvegCost=TotalAvegCost+[aveg doubleValue];
                }else{
                    SubtotalValue=pricevalue;
                    TaxValue=(([tax doubleValue]*pricevalue)/100);
                    Grandvalue=SubtotalValue+TaxValue;
                    TotalAvegCost=[aveg doubleValue];
                }
                
                
            }
            SubTotalstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",SubtotalValue];
            TaxValueStr = [NSString stringWithFormat:@"%@%.02f", @"$ ",TaxValue];
            GrandTotalstr=[NSString stringWithFormat:@"%@%.02f", @"$ ",Grandvalue];
        
            taxDlbl.text=TaxValueStr;
            SubTDisplaylbl.text=SubTotalstr;
            GTotalDlbl.text=GrandTotalstr;
            
         [ProductslistTable reloadData];
        
    }else{
        UIAlertView *itemalert=[[UIAlertView alloc]initWithTitle:@"Alert" message:@"Enter Discount" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
        [itemalert show];
        itemalert=nil;
    }

    }
    itemselected=NO,SubTotalstr=nil,TaxValueStr=nil,GrandTotalstr=nil,tax=nil,price=nil,aveg=nil;
}
-(void)CancelChangeDiscount
{
   [self discountViewremoveMethod];
    
}
-(void)ChangequantityClicked
{
    if (RecallinvoiceValue==YES){
        [Quantitybtn removeTarget:nil
                           action:NULL
                 forControlEvents:UIControlEventAllEvents];
    }else{
    if (itemselected){
        if (!QuantityPopupView)
        QuantityPopupView=[[UIView alloc]init];
        if (isLandScope) {
            QuantityPopupView.frame=CGRectMake(0, 0, 1024, 768);
        }else{
            
            QuantityPopupView.frame=CGRectMake(0, 0, 768, 1024);
        }
        [QuantityPopupView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
        [self.view addSubview:QuantityPopupView];
         if (!Quantityview)
        Quantityview=[[UIScrollView alloc]init];
        if (isLandScope){
            Quantityview.frame=CGRectMake(200, 200, QuantityPopupView.frame.size.width-400, QuantityPopupView.frame.size.height-450);
        }else{
            Quantityview.frame=CGRectMake(150, 300, QuantityPopupView.frame.size.width-300, QuantityPopupView.frame.size.height-750);
        }
        
        [Quantityview setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
        
        [Quantityview.layer setBorderWidth:2.0];
        [Quantityview.layer setBorderColor:[[UIColor whiteColor] CGColor]];
        //AddvendorsView.layer.cornerRadius=8;
        [QuantityPopupView addSubview:Quantityview];
        
        
        CGFloat instwidth=(Quantityview.frame.size.width)/2;
        CGFloat inst=instwidth/2;
          if (!QTextlbl)
        QTextlbl=[[UILabel alloc] init];
        QTextlbl.frame=CGRectMake(inst-60, 25,instwidth, 50);
        
        [QTextlbl setFont:[UIFont systemFontOfSize:25.0f]];
        [QTextlbl setBackgroundColor:[UIColor clearColor]];
        [QTextlbl setTextColor:[UIColor whiteColor]];
        [QTextlbl setText:@"Enter Quantity"];
        QTextlbl.lineBreakMode = NSLineBreakByWordWrapping;
        QTextlbl.numberOfLines = 2;
        [QTextlbl setTextAlignment:NSTextAlignmentLeft];
        [Quantityview addSubview:QTextlbl];
          if (!ChangeQuantityField)
        ChangeQuantityField=[[UITextField alloc] init];
        //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
        ChangeQuantityField.frame=CGRectMake(inst-20, 95,instwidth+50, 40);
        ChangeQuantityField.delegate=self;
        
        UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
        // // //NSLog(@"%f",GeneralinfoField.frame.origin.y);
        ChangeQuantityField.leftView = paddingview;
        ChangeQuantityField.keyboardType=UIKeyboardTypeNumberPad;
        ChangeQuantityField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        ChangeQuantityField.leftViewMode = UITextFieldViewModeAlways;
        [ChangeQuantityField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
        [ChangeQuantityField setAutocorrectionType:UITextAutocorrectionTypeNo];
        [Quantityview addSubview:ChangeQuantityField];
        [paddingview removeFromSuperview],paddingview=nil;
        @autoreleasepool {
            SaveQtyBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            
            SaveQtyBtn.frame=CGRectMake(instwidth-90, 180, 80, 30);
            [SaveQtyBtn addTarget:self action:@selector(SaveChangeQuantity) forControlEvents:UIControlEventTouchUpInside];
            
            //[SaveTaxButton setTitle:@"Save" forState:UIControlStateNormal];
            [SaveQtyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [SaveQtyBtn setBackgroundImage:[UIImage imageNamed:@"savegreenbutton.png"] forState:UIControlStateNormal];
            [Quantityview addSubview:SaveQtyBtn];
            
            CancelQtyBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            
            CancelQtyBtn.frame=CGRectMake(instwidth+40, 180, 80, 30);
            [CancelQtyBtn addTarget:self action:@selector(CancelChangeQuantity) forControlEvents:UIControlEventTouchUpInside];
            [CancelQtyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [CancelQtyBtn setBackgroundImage:[UIImage imageNamed:@"cancelgreenbutton.png"] forState:UIControlStateNormal];
            // [CancelTaxButton setTitle:@"Cancel" forState:UIControlStateNormal];
            [Quantityview addSubview:CancelQtyBtn];

        }
        
    }else{
        
        [self.view makeToast:@"SelectItem"];
    }

  }
}
-(void)payViewMethod
{
    if (!PaypopupView)
        PaypopupView=[[UIView alloc]init];
    if (isLandScope) {
        PaypopupView.frame=CGRectMake(0, 0, 1024, 768);
    }
    
    else{
        
        PaypopupView.frame=CGRectMake(0, 0, 768, 1024);
    }
    [PaypopupView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:PaypopupView];
    if (!PayView)
        PayView=[[UIScrollView alloc]init];
    if (isLandScope){
        PayView.frame=CGRectMake(225, 50, PaypopupView.frame.size.width-450, PaypopupView.frame.size.height-100);
        
        //PayView.contentSize=CGSizeMake(PaypopupView.frame.size.width-450, PaypopupView.frame.size.height+100);
    }else{
        PayView.frame=CGRectMake(150, 200, PaypopupView.frame.size.width-300, PaypopupView.frame.size.height-400);
    }
    
    [PayView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    //[Discountview setBackgroundColor:[UIColor blackColor]];
    
    [PayView.layer setBorderWidth:2.0];
    [PayView.layer setBorderColor:[[UIColor whiteColor] CGColor]];
    //AddvendorsView.layer.cornerRadius=8;
    [PaypopupView addSubview:PayView];
    
    CGFloat payw=PayView.frame.size.width/2;
    if (!Amountlbl)
        Amountlbl=[[UILabel alloc] init];
    Amountlbl.frame=CGRectMake(20, 10,payw, 40);
    
    [Amountlbl setFont:[UIFont systemFontOfSize:20.0f]];
    [Amountlbl setBackgroundColor:[UIColor clearColor]];
    [Amountlbl setTextColor:[UIColor whiteColor]];
    [Amountlbl setText:@"Amount"];
    Amountlbl.lineBreakMode = NSLineBreakByWordWrapping;
    Amountlbl.numberOfLines = 2;
    [Amountlbl setTextAlignment:NSTextAlignmentLeft];
    [PayView addSubview:Amountlbl];
    if (!AmountField)
        AmountField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    AmountField.frame=CGRectMake(20, 50,payw-30, 40);
    AmountField.delegate=self;
    
    UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    // // //NSLog(@"%f",GeneralinfoField.frame.origin.y);
    AmountField.text=GTotalDlbl.text;
    AmountField.leftView = paddingview;
    AmountField.keyboardType=UIKeyboardTypeNumberPad;
    AmountField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    AmountField.leftViewMode = UITextFieldViewModeAlways;
    [AmountField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
    [AmountField setAutocorrectionType:UITextAutocorrectionTypeNo];
    [PayView addSubview:AmountField];
    [paddingview removeFromSuperview],paddingview=nil;
    if (!GivenAmountlbl)
        GivenAmountlbl=[[UILabel alloc] init];
    GivenAmountlbl.frame=CGRectMake(20, 100,payw, 40);
    
    [GivenAmountlbl setFont:[UIFont systemFontOfSize:20.0f]];
    [GivenAmountlbl setBackgroundColor:[UIColor clearColor]];
    [GivenAmountlbl setTextColor:[UIColor whiteColor]];
    [GivenAmountlbl setText:@"Given Amount"];
    GivenAmountlbl.lineBreakMode = NSLineBreakByWordWrapping;
    GivenAmountlbl.numberOfLines = 2;
    [GivenAmountlbl setTextAlignment:NSTextAlignmentLeft];
    [PayView addSubview:GivenAmountlbl];
    if (!GivenAmountField)
        GivenAmountField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    GivenAmountField.frame=CGRectMake(20, 150,payw-30, 40);
    GivenAmountField.delegate=self;
    GivenAmountField.text=GTotalDlbl.text;
    UIView *paddingview2=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    // // //NSLog(@"%f",GeneralinfoField.frame.origin.y);
    GivenAmountField.leftView = paddingview2;
    GivenAmountField.keyboardType=UIKeyboardTypeNumberPad;
    GivenAmountField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    GivenAmountField.leftViewMode = UITextFieldViewModeAlways;
    [GivenAmountField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
    [GivenAmountField setAutocorrectionType:UITextAutocorrectionTypeNo];
    [PayView addSubview:GivenAmountField];
     [paddingview2 removeFromSuperview],paddingview2=nil;
    if (!DeleteGivenAmntBtn)
        DeleteGivenAmntBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [DeleteGivenAmntBtn setFrame:CGRectMake(GivenAmountField.frame.size.width-30,8, 25, 25)];
    //[editBtn setTitle:@"edit" forState:UIControlStateNormal];
    [DeleteGivenAmntBtn setImage:[UIImage imageNamed:@"removered.png"] forState:UIControlStateNormal];
    [DeleteGivenAmntBtn setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
    [DeleteGivenAmntBtn addTarget:self action:@selector(DeleteGivenAmt) forControlEvents:UIControlEventTouchUpInside];
    
    [GivenAmountField addSubview:DeleteGivenAmntBtn];
    if (!Paytypelbl)
        Paytypelbl=[[UILabel alloc] init];
    Paytypelbl.frame=CGRectMake(20, 200,payw, 40);
    [Paytypelbl setFont:[UIFont systemFontOfSize:20.0f]];
    [Paytypelbl setBackgroundColor:[UIColor clearColor]];
    [Paytypelbl setTextColor:[UIColor whiteColor]];
    [Paytypelbl setText:@"Pay Type"];
    Paytypelbl.lineBreakMode = NSLineBreakByWordWrapping;
    Paytypelbl.numberOfLines = 2;
    [Paytypelbl setTextAlignment:NSTextAlignmentLeft];
    [PayView addSubview:Paytypelbl];
    if (!paytypesArray)
        paytypesArray=[[NSArray alloc]initWithObjects:@"Cash",@"Cheque",@"Card", nil];
    if (!CashDropDown)
        CashDropDown = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    CashDropDown.frame=CGRectMake(20,250,payw-20,40);
    [CashDropDown addTarget:self action:@selector(cashtypeClicked) forControlEvents:UIControlEventTouchUpInside];
    [CashDropDown setTitle:[paytypesArray objectAtIndex:0] forState:UIControlStateNormal];
    [CashDropDown setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [CashDropDown setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    [PayView addSubview:CashDropDown];
    
    
    if (!CashlistTable)
        CashlistTable = [[UITableView alloc] initWithFrame:CGRectMake(20,290,payw-20,100) style:UITableViewStylePlain];
    CashlistTable.backgroundColor=[UIColor whiteColor];
    CashlistTable.delegate = self;
    CashlistTable.dataSource = self;
    CashlistTable.scrollEnabled = YES;
    CashlistTable.hidden=YES;
    [CashlistTable.layer setBorderWidth: 1.0];
    [CashlistTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [PayView addSubview:CashlistTable];
    
    if (!SplitInvoiceTable)
        SplitInvoiceTable = [[UITableView alloc] initWithFrame:CGRectMake(Amountlbl.frame.size.width, 60,payw-10, 180) style:UITableViewStylePlain];
    SplitInvoiceTable.backgroundColor=[UIColor whiteColor];
    SplitInvoiceTable.delegate = self;
    SplitInvoiceTable.dataSource = self;
    SplitInvoiceTable.scrollEnabled = YES;
    SplitInvoiceTable.hidden=YES;
    [SplitInvoiceTable.layer setBorderWidth: 1.0];
    [SplitInvoiceTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [PayView addSubview:SplitInvoiceTable];
    if (!SelectPrinterlabel)
        SelectPrinterlabel=[[UILabel alloc] init];
    SelectPrinterlabel.frame=CGRectMake(20, 200,payw, 40);
    
    [SelectPrinterlabel setFont:[UIFont systemFontOfSize:20.0f]];
    [SelectPrinterlabel setBackgroundColor:[UIColor clearColor]];
    [SelectPrinterlabel setTextColor:[UIColor whiteColor]];
    [SelectPrinterlabel setText:@"Select Printer"];
    SelectPrinterlabel.lineBreakMode = NSLineBreakByWordWrapping;
    SelectPrinterlabel.numberOfLines = 2;
    [SelectPrinterlabel setTextAlignment:NSTextAlignmentLeft];
    // [PayView addSubview:SelectPrinterlabel];
    
    if (!SelectPrinterBtn)
        SelectPrinterBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    SelectPrinterBtn.frame=CGRectMake(20,250,payw-20,40);
    [SelectPrinterBtn addTarget:self action:@selector(PrintertypeClicked) forControlEvents:UIControlEventTouchUpInside];
    //[SelectPrinterBtn setTitle:[paytypesArray objectAtIndex:0] forState:UIControlStateNormal];
    [SelectPrinterBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [SelectPrinterBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    //[PayView addSubview:SelectPrinterBtn];
    
    if (!PayPrinterDataTable)
        PayPrinterDataTable = [[UITableView alloc] initWithFrame:CGRectMake(20,290,payw-20,100) style:UITableViewStylePlain];
    PayPrinterDataTable.backgroundColor=[UIColor whiteColor];
    PayPrinterDataTable.delegate = self;
    PayPrinterDataTable.dataSource = self;
    PayPrinterDataTable.scrollEnabled = YES;
    PayPrinterDataTable.hidden=YES;
    [PayPrinterDataTable.layer setBorderWidth: 1.0];
    [PayPrinterDataTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    // [PayView addSubview:PayPrinterDataTable];
    
     if (!SelectPrinterlabel)
    SelectPrinterlabel=[[UILabel alloc] init];
    SelectPrinterlabel.frame=CGRectMake(Amountlbl.frame.size.width+10, 200,payw, 40);
    [SelectPrinterlabel setFont:[UIFont systemFontOfSize:20.0f]];
    [SelectPrinterlabel setBackgroundColor:[UIColor clearColor]];
    [SelectPrinterlabel setTextColor:[UIColor whiteColor]];
    [SelectPrinterlabel setText:@"Do you want Receipt?"];
    SelectPrinterlabel.lineBreakMode = NSLineBreakByWordWrapping;
    SelectPrinterlabel.numberOfLines = 2;
    [SelectPrinterlabel setTextAlignment:NSTextAlignmentLeft];
    //[PayView addSubview:SelectPrinterlabel];
    
    
     if (!PrinterSwitch)
    PrinterSwitch=[[UISwitch alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    PrinterSwitch.frame=CGRectMake(Amountlbl.frame.size.width-30+Amountlbl.frame.size.width/2,255,100,40);
    
    [PrinterSwitch addTarget:self action:@selector(PrinterswitchClicked:) forControlEvents:UIControlEventValueChanged];
    [PrinterSwitch setOn:TRUE animated:YES];
    PrinterswitchValue=@"yes";
    //[PayView addSubview:PrinterSwitch];
    
    CGFloat cashw=PayView.frame.size.width/6;
    NSString *givenamtstr = [GTotalDlbl.text stringByReplacingOccurrencesOfString:@"$ " withString:@""];
    float myFloat=[givenamtstr floatValue];
    int result = (int)roundf(myFloat);
    CGFloat Wd=12;
    for (int i=0; i<6; i++)
    {
        AmountBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        NSMutableArray *payArray;
        if (!payArray)
        payArray=[[NSMutableArray alloc]initWithObjects:@"1",@"5",@"10",@"20",@"50", nil];
        [payArray addObject:[NSString stringWithFormat:@"%d",result]];
        AmountBtn.frame=CGRectMake(Wd,450,cashw-10,40);
        [AmountBtn addTarget:self action:@selector(AmountClicked:) forControlEvents:UIControlEventTouchUpInside];
        AmountBtn.tag=i+100;
        [AmountBtn setTitle:[payArray objectAtIndex:i] forState:UIControlStateNormal];
        [AmountBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [AmountBtn setBackgroundImage:[UIImage imageNamed:@"fetch-cancel-button.png"] forState:UIControlStateNormal];
        
        [PayView addSubview:AmountBtn];
        
        Wd=Wd+cashw-5;
        
        
    }
    if (!SavePayBtn)
    SavePayBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    SavePayBtn.frame=CGRectMake(payw-100, 550, 80, 40);
    [SavePayBtn addTarget:self action:@selector(SavePay) forControlEvents:UIControlEventTouchUpInside];
    [SavePayBtn setTitle:@"Pay" forState:UIControlStateNormal];
    [SavePayBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [SavePayBtn setBackgroundImage:[UIImage imageNamed:@"okay-button.png"] forState:UIControlStateNormal];
    [PayView addSubview:SavePayBtn];
    
    if (!CancelPayBtn)
    CancelPayBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    CancelPayBtn.frame=CGRectMake(SavePayBtn.frame.size.width+payw-60, 550, 80, 40);
    [CancelPayBtn addTarget:self action:@selector(Cancelpay) forControlEvents:UIControlEventTouchUpInside];
    [CancelPayBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [CancelPayBtn setBackgroundImage:[UIImage imageNamed:@"okay-button.png"] forState:UIControlStateNormal];
    [CancelPayBtn setTitle:@"Cancel" forState:UIControlStateNormal];
    [PayView addSubview:CancelPayBtn];
}
-(void)Clearpaymethod
{
    [ItemNamesArray removeAllObjects];
    [ItemNosArray removeAllObjects];
    [QntysArray removeAllObjects];
    [pricesArray removeAllObjects];
    [SnosArray removeAllObjects];
    [TaxesArray removeAllObjects];
    [AvegCostsArray removeAllObjects];
    [DiscountsArray removeAllObjects];
    
    [ItemVendorArray removeAllObjects];
    [ItemDeptsArray removeAllObjects];
    [ItemDesArray removeAllObjects];
    [ProductslistTable reloadData];
    
    SubTDisplaylbl.text=@"$ 0.00";
    taxDlbl.text=@"$ 0.00";
    GTotalDlbl.text=@"$ 0.00";
    
    [PayBtn setTitle:@"Pay" forState:UIControlStateNormal];
    
    RecallinvoiceValue=NO;
    
    [SearchBtn addTarget:self action:@selector(SearchBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [DeleteBtn addTarget:self action:@selector(DeleteAllDataClicked) forControlEvents:UIControlEventTouchUpInside];
    [DiscountBtn addTarget:self action:@selector(ChangeDiscountClicked) forControlEvents:UIControlEventTouchUpInside];
    [PriceChangeBtn addTarget:self action:@selector(PriceChangeClciked) forControlEvents:UIControlEventTouchUpInside];
    
    [CreditBtn addTarget:self action:@selector(CreditBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [CheckBtn addTarget:self action:@selector(CheckBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [CashBtn addTarget:self action:@selector(CashBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [VoidInVoiceBtn addTarget:self action:@selector(VoidinVoiceClicked) forControlEvents:UIControlEventTouchUpInside];
    [ItemBtn addTarget:self action:@selector(ItemClicked:) forControlEvents:UIControlEventTouchUpInside];
    [FindBtn addTarget:self action:@selector(FindCustomerClicked) forControlEvents:UIControlEventTouchUpInside];
    [AddBtn addTarget:self action:@selector(AddCustomerClicked) forControlEvents:UIControlEventTouchUpInside];
    [retraiveOnHoldBtn addTarget:self action:@selector(FetchOnHoldClicked) forControlEvents:UIControlEventTouchUpInside];
}
-(void)PayBtnClicked
{
    splitAmoutsArray=nil;
    SplitpaymentsArray=nil;
    [SplitDataTable reloadData];
   
    invoice_id=@"";
    SplitInvoiceID=@"";
   
    
   // // //NSLog(@"split amounts %@",splitAmoutsArray);
    
    if ([[generalDataObject  userType] isEqualToString:@"employee"]){
        if ([[generalDataObject  end_transaction_permission] isEqualToString:@"yes"]){
            
            NSString *paystr=[NSString stringWithFormat:@"%@",PayBtn.titleLabel.text];
              //[PayBtn setTitle:@"Clear Invoice" forState:UIControlStateNormal];
            
            if ([paystr isEqualToString:@"Clear Display"]){
                [self Clearpaymethod];
                
            }else{
                [self payViewMethod];
            
            }
            paystr=nil;
        }else{
            UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
            
            [authalert show];
            authalert=nil;
        }
    } else{
     
     NSString *paystr=[NSString stringWithFormat:@"%@",PayBtn.titleLabel.text];
     //[PayBtn setTitle:@"Clear Invoice" forState:UIControlStateNormal];
     
     if ([paystr isEqualToString:@"Clear Display"]){
       
         
         [self Clearpaymethod];
     }
     else
     {
         [self payViewMethod];
     }
        paystr=nil;
}

}
-(void)DeleteGivenAmt
{
    GivenAmountField.text=@"";
    
}
-(void) removeallProductDatamethod
{
    [ProductslistTable removeFromSuperview];
}
-(void)SavePay
{
    
   InvoiceCheckNo=@"";
    NSString *amoutstr=AmountField.text;
    NSString *givenamtstr=GivenAmountField.text;
    amoutstr = [amoutstr stringByReplacingOccurrencesOfString:@"$ " withString:@""];
    givenamtstr = [givenamtstr stringByReplacingOccurrencesOfString:@"$ " withString:@""];
    split_amount=givenamtstr;
    amount=[amoutstr doubleValue];
    givenamout=[givenamtstr doubleValue];
    self.amountString=AmountField.text;
    paymentType=[NSString stringWithFormat:@"%@",CashDropDown.titleLabel.text];
    
    if ([paymentType isEqualToString:@"Cash"]){
        [self CashTypePaymentMethod];
    }else if ([paymentType isEqualToString:@"Cheque"]){
        [self CheckTypePaymentMethod];
        
    }else if ([paymentType isEqualToString:@"Card"]){
        
        [self CreditTypepaymentMethod];
        
    }
    amoutstr=nil,givenamtstr=nil;
}
-(void)CreditTypepaymentMethod
{
    NSString *querySQL = [NSString stringWithFormat: @"SELECT paymentprocessorname FROM paymentprocessorpreferencess"];
    NSMutableArray *paymenttypesArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:paymenttypesArray];
    
    NSMutableDictionary *cardDict;
    if (!cardDict)
    cardDict=[[NSMutableDictionary alloc]init];
    if ([paymenttypesArray count]>0)
    {
        cardDict=[paymenttypesArray objectAtIndex:0];
    }
    
    NSString *CardpaymentType=[cardDict objectForKey:@"paymentprocessorname"];
    
    if ([CardpaymentType isEqualToString:@"Express Manual"]){
        if (givenamout>=amount){
        double value=givenamout-amount;
            remainingamountstr = [NSString stringWithFormat:@"%.02f", value];
            
              [self payViewRemovingMethod];
           
            
            if (Myswitch.on){
                if ([HoldID length]>0){
                    
                    if ([SplitInvoiceID length]>0){
                        HoldStatus=@"complete";
                        paymentType=@"multiple";
                        invoiceID=SplitInvoiceID;
                        [self UpdateInVoiceDataMethod];
                        // [self SaveInvoiceDataMethod];
                        
                        split_amount=GivenAmountField.text;
                        payment_type=@"Card";
                        
                        [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                        [self SaveSplitInvoiceMethod];
                        PrintSplitInvoiceID=SplitInvoiceID;
                        [self SplitPrintStringMethod];
                        SplitInvoiceID=@"";
                        
                    }else{
                        HoldStatus=@"complete";
                        [self UpdateInVoiceDataMethod];
                        
                        
                        payment_type=@"Card";
                        //[self SaveInvoiceDataMethod];
                        
                        [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                        TotalPaymetType=@"Card";
                        [self EqualPrintStringMethod];
                    }
                    
                    HoldID=@"";
                    invoiceID=@"";
                    
                }else{
                    if ([SplitInvoiceID length]>0){
                        HoldStatus=@"complete";
                        paymentType=@"multiple";
                        invoiceID=SplitInvoiceID;
                        [self UpdateInVoiceDataMethod];
                        //[self SaveInvoiceDataMethod];
                        split_amount=GivenAmountField.text;
                        payment_type=@"Card";
                        
                        [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                        [self SaveSplitInvoiceMethod];
                        PrintSplitInvoiceID=SplitInvoiceID;
                        [self SplitPrintStringMethod];
                        SplitInvoiceID=@"";
                        
                    }else{
                        paymentType=@"Card";
                        HoldStatus=@"complete";
                        invoiceID=[generalDataObject  getDeviceID];
                        
                        [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                        [self SaveInvoiceDataMethod];
                        
                        TotalPaymetType=@"Card";
                        [self EqualPrintStringMethod];
            
                    }
                    
                }
                
            }
        
            [self PrinterDataMethod];
            
            [ItemNamesArray removeAllObjects];
            [ItemNosArray removeAllObjects];
            [QntysArray removeAllObjects];
            [pricesArray removeAllObjects];
            [SnosArray removeAllObjects];
            [TaxesArray removeAllObjects];
            [AvegCostsArray removeAllObjects];
            [DiscountsArray removeAllObjects];
            
            [ItemVendorArray removeAllObjects];
            [ItemDeptsArray removeAllObjects];
            [ItemDesArray removeAllObjects];
            
            [ProductslistTable reloadData];
            SubTDisplaylbl.text=@"$ 0.00";
            taxDlbl.text=@"$ 0.00";
            GTotalDlbl.text=@"$ 0.00";
            
        }else{
            [self SplitpayMethod];
            
        }
    }else  if ([CardpaymentType isEqualToString:@"Mercury"]){
        
        
        
        NSString *merquerySQL = [NSString stringWithFormat: @"SELECT mercury_primary_url,mercury_secondary_url,mercury_merchant_id,mercury_password FROM mercury_pay_table"];
        NSMutableArray *mercuryArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:merquerySQL resultsArray:mercuryArray];
        
        if ([mercuryArray count]>0)
        {
            NSDictionary *Dict=[mercuryArray objectAtIndex:0];
            
            SwipeViewController *swipeViewController=[[SwipeViewController alloc]initWithNibName:@"SwipeViewController" bundle:Nil];
            PaymentDTO *merchant = [PaymentDTO new];
            merchant.password =[Dict objectForKey:@"mercury_password"];
            merchant.merchantId =[Dict objectForKey:@"mercury_merchant_id"];
            merchant.primaryUrl=[Dict objectForKey:@"mercury_primary_url"];
             invoiceID=[generalDataObject  getDeviceID];
            merchant.purchase = [NSString stringWithFormat:@"%0.2f",givenamout];
            swipeViewController.merchantInfo=merchant;
            swipeViewController.invoiceNo=invoiceID;
            [self.navigationController pushViewController:swipeViewController animated:NO];
            
           [mercuryArray removeAllObjects],Dict=Nil;
          // merchnatname=address1=address2=phno=zipcode=nil;
        }
        
       
    }
    cardDict=nil,CardpaymentType=nil;
}


-(void)saveapproveCardDataMethod:(NSString *)paymentresult
{
      split_amount=paymentresult;
    //NSLog(@"%@",self.amountString);
    NSString *amountstr=self.amountString;
    amountstr = [amountstr stringByReplacingOccurrencesOfString:@"$ " withString:@""];
    amount=[amountstr doubleValue];
   // NSLog(@"amount %@",paymentresult);
    givenamout=[paymentresult doubleValue];
   // NSLog(@"%f",amount);
    if (givenamout>=amount){
        double value=givenamout-amount;
        remainingamountstr = [NSString stringWithFormat:@"%.02f", value];
        
        [self payViewRemovingMethod];
        [PaypopupView removeFromSuperview];
        
        if (Myswitch.on){
            if ([HoldID length]>0){
                
                if ([SplitInvoiceID length]>0){
                    HoldStatus=@"complete";
                    paymentType=@"multiple";
                    invoiceID=SplitInvoiceID;
                    [self UpdateInVoiceDataMethod];
                    // [self SaveInvoiceDataMethod];
                    
                    split_amount=paymentresult;
                    payment_type=@"Card";
                    
                    [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                    [self SaveSplitInvoiceMethod];
                    PrintSplitInvoiceID=SplitInvoiceID;
                    [self SplitPrintStringMethod];
                    SplitInvoiceID=@"";
                    
                }else{
                    HoldStatus=@"complete";
                    [self UpdateInVoiceDataMethod];
                    
                    
                    payment_type=@"Card";
                    //[self SaveInvoiceDataMethod];
                    
                    [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                    TotalPaymetType=@"Card";
                    [self EqualPrintStringMethod];
                }
                
                HoldID=@"";
                invoiceID=@"";
                
            }else{
                if ([SplitInvoiceID length]>0){
                    HoldStatus=@"complete";
                    paymentType=@"multiple";
                    invoiceID=SplitInvoiceID;
                    [self UpdateInVoiceDataMethod];
                    //[self SaveInvoiceDataMethod];
                    split_amount=paymentresult;
                    payment_type=@"Card";
                    
                    [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                    [self SaveSplitInvoiceMethod];
                    PrintSplitInvoiceID=SplitInvoiceID;
                    [self SplitPrintStringMethod];
                    SplitInvoiceID=@"";
                    
                }else{
                    paymentType=@"Card";
                    HoldStatus=@"complete";
                    //invoiceID=[generalDataObject  getDeviceID];
                    
                    [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                    [self SaveInvoiceDataMethod];
                    
                    TotalPaymetType=@"Card";
                    [self EqualPrintStringMethod];
                    
                }
                
            }
        }
        [self PrinterDataMethod];
        
     
        
        [ItemNamesArray removeAllObjects];
        [ItemNosArray removeAllObjects];
        [QntysArray removeAllObjects];
        [pricesArray removeAllObjects];
        [SnosArray removeAllObjects];
        [TaxesArray removeAllObjects];
        [AvegCostsArray removeAllObjects];
        [DiscountsArray removeAllObjects];
        
        [ItemVendorArray removeAllObjects];
        [ItemDeptsArray removeAllObjects];
        [ItemDesArray removeAllObjects];
        
        [ProductslistTable reloadData];
        SubTDisplaylbl.text=@"$ 0.00";
        taxDlbl.text=@"$ 0.00";
        GTotalDlbl.text=@"$ 0.00";
        
    }else{
        [self SplitpayMethod];
        
    }
    
}
//-----------------------------------------------------------------------------
#pragma mark - mercury card  methods -
//-----------------------------------------------------------------------------
-(void) PrinterDataMethod
{
    if ([PrinterIpsArray count]>0)
    {
        NSUInteger objIdx = [PrinterIpsArray containsObject:@"printer1"];
        // //NSLog(@"%lu",(unsigned long)objIdx);
        if(objIdx == 0)
        {
            
            PayPrinterName=[printernamesArray objectAtIndex:0];
            
            printChar=[printcharArray objectAtIndex:0];
            
            font=[FontsArray objectAtIndex:0];
            align=[AlignsArray objectAtIndex:0];
            language=[languagesArray objectAtIndex:0];
            Pwidth=[WidthsArray objectAtIndex:0];
            Pheight=[HeightsArray objectAtIndex:0];
            
            Bold=[boldsArray objectAtIndex:0];
            Underline=[UnderlinesArray objectAtIndex:0];
            
            xposition =[XpossArray objectAtIndex:0];
            spacing=[spacingsArray objectAtIndex:0];
            
            Ipadd=[IpAddsArray objectAtIndex:0];
            
            unit=[unitsArray objectAtIndex:0];
            Dbprintertype=[DBPrintertypesArray objectAtIndex:0];
            SearchPrinterStr=[searchPrinterArray objectAtIndex:0];
            
            
        }
        else
        {
            NSInteger indexno=[PrinterIpsArray indexOfObject:@"printer1"];
            
            
            PayPrinterName=[printernamesArray objectAtIndex:indexno];
            
            printChar=[printcharArray objectAtIndex:indexno];
            
            font=[FontsArray objectAtIndex:indexno];
            align=[AlignsArray objectAtIndex:indexno];
            language=[languagesArray objectAtIndex:indexno];
            Pwidth=[WidthsArray objectAtIndex:indexno];
            Pheight=[HeightsArray objectAtIndex:indexno];
            
            Bold=[boldsArray objectAtIndex:indexno];
            Underline=[UnderlinesArray objectAtIndex:indexno];
            
            xposition =[XpossArray objectAtIndex:indexno];
            spacing=[spacingsArray objectAtIndex:indexno];
            
            Ipadd=[IpAddsArray objectAtIndex:indexno];
            
            unit=[unitsArray objectAtIndex:indexno];
            Dbprintertype=[DBPrintertypesArray objectAtIndex:indexno];
            SearchPrinterStr=[searchPrinterArray objectAtIndex:indexno];
            
        }
        
        //[self GetPrint];
        
        
    }

}
-(void)CashTypePaymentMethod
{
    if (givenamout>=amount)
    {
        
        double value=givenamout-amount;
        remainingamountstr = [NSString stringWithFormat:@"%.02f", value];
        Changealert=[[UIAlertView alloc]initWithTitle:@"Remaining Change" message:[NSString stringWithFormat:@"%@%@",@"Change is  ",remainingamountstr] delegate:self
                                    cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
        
        [Changealert show];
          [self payViewRemovingMethod];
        [PaypopupView removeFromSuperview];
        
        if (Myswitch.on)
        {
            if ([HoldID length]>0)
            {
                
                if ([SplitInvoiceID length]>0)
                {
                    HoldStatus=@"complete";
                    paymentType=@"multiple";
                    invoiceID=SplitInvoiceID;
                    [self UpdateInVoiceDataMethod];
                    // [self SaveInvoiceDataMethod];
                    
                    split_amount=GivenAmountField.text;
                    payment_type=@"Cash";
                    
                    [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                    [self SaveSplitInvoiceMethod];
                    PrintSplitInvoiceID=SplitInvoiceID;
                    [self SplitPrintStringMethod];
                    SplitInvoiceID=@"";
                    
                }
                else
                {
                    HoldStatus=@"complete";
                    [self UpdateInVoiceDataMethod];
                    
                    
                    paymentType=@"Cash";
                    //[self SaveInvoiceDataMethod];
                    
                    [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                    TotalPaymetType=@"Cash";
                    [self EqualPrintStringMethod];
                }
                
                HoldID=@"";
                invoiceID=@"";
                
            }
            else
            {
                if ([SplitInvoiceID length]>0)
                {
                    HoldStatus=@"complete";
                    paymentType=@"multiple";
                    invoiceID=SplitInvoiceID;
                    [self UpdateInVoiceDataMethod];
                    //[self SaveInvoiceDataMethod];
                    split_amount=GivenAmountField.text;
                    payment_type=@"Cash";
                    
                    [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                    [self SaveSplitInvoiceMethod];
                    PrintSplitInvoiceID=SplitInvoiceID;
                    [self SplitPrintStringMethod];
                    SplitInvoiceID=@"";
                    
                }
                else
                {
                    paymentType=@"Cash";
                    HoldStatus=@"complete";
                    invoiceID=[generalDataObject  getDeviceID];
                    
                    [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                    [self SaveInvoiceDataMethod];
                    
                    TotalPaymetType=@"Cash";
                    [self EqualPrintStringMethod];
                    
                    
                }
                
            }
            
        }
     
        
        [ItemNamesArray removeAllObjects];
        [ItemNosArray removeAllObjects];
        [QntysArray removeAllObjects];
        [pricesArray removeAllObjects];
        [SnosArray removeAllObjects];
        [TaxesArray removeAllObjects];
        [AvegCostsArray removeAllObjects];
        [DiscountsArray removeAllObjects];
        
        [ItemVendorArray removeAllObjects];
        [ItemDeptsArray removeAllObjects];
        [ItemDesArray removeAllObjects];
        
        [ProductslistTable reloadData];
        SubTDisplaylbl.text=@"$ 0.00";
        taxDlbl.text=@"$ 0.00";
        GTotalDlbl.text=@"$ 0.00";
        
    }
    else
    {
        [self SplitpayMethod];
        
        
    }

}
-(void)CheckTypePaymentMethod
{
    checkPopUp=[[UIView alloc]init];
    if (isLandScope)
    {
        checkPopUp.frame=CGRectMake(0, 0, 1024, 768);
    }
    
    else{
        
        checkPopUp.frame=CGRectMake(0, 0, 768, 1024);
    }
    [checkPopUp setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:checkPopUp];
    
    checkPopUpPay=[[UIView alloc]init];
    
    if (isLandScope)
    {
        checkPopUpPay.frame=CGRectMake(250, 150, checkPopUp.frame.size.width-500, checkPopUp.frame.size.height-530);
        
        // checkPopUpPay.contentSize=CGSizeMake(checkPopUp.frame.size.width-450, checkPopUp.frame.size.height+100);
    }
    else
    {
        checkPopUpPay.frame=CGRectMake(150, 200, checkPopUp.frame.size.width-300, checkPopUp.frame.size.height-800);
    }
    
    [checkPopUpPay setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    //[Discountview setBackgroundColor:[UIColor blackColor]];
    
    [checkPopUpPay.layer setBorderWidth:2.0];
    [checkPopUpPay.layer setBorderColor:[[UIColor whiteColor] CGColor]];
    //AddvendorsView.layer.cornerRadius=8;
    [checkPopUp addSubview:checkPopUpPay];
    
    
    
    CGFloat vwidth=checkPopUpPay.frame.size.width/2;
    
    checkNumLbl=[[UILabel alloc] init];
    checkNumLbl.frame=CGRectMake(vwidth-100, 20,300,40);
    
    [checkNumLbl setFont:[UIFont systemFontOfSize:25.0f]];
    [checkNumLbl setBackgroundColor:[UIColor clearColor]];
    [checkNumLbl setTextColor:[UIColor whiteColor]];
    [checkNumLbl setText:@"Enter cheque Number"];
    checkNumLbl.lineBreakMode = NSLineBreakByWordWrapping;
    checkNumLbl.numberOfLines = 2;
    [checkNumLbl setTextAlignment:NSTextAlignmentLeft];
    [checkPopUpPay addSubview:checkNumLbl];
    
    
    checkNumTxt=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    checkNumTxt.frame=CGRectMake(vwidth-160,70,vwidth+100,40);
    
    checkNumTxt.placeholder = @"Enter cheque Number";
    checkNumTxt.keyboardType=UIKeyboardTypeNumberPad;
    checkNumTxt.textAlignment= NSTextAlignmentLeft;
    checkNumTxt.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    checkNumTxt.leftViewMode = UITextFieldViewModeAlways;
    [checkNumTxt setBackground:[UIImage imageNamed:@"productscanbutton.png"]];
    [checkNumTxt setAutocorrectionType:UITextAutocorrectionTypeNo];
    [checkPopUpPay addSubview:checkNumTxt];
    
    checkNumBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    checkNumBtn.frame=CGRectMake(vwidth-30, 150, 80, 40);
    [checkNumBtn addTarget:self action:@selector(CheckokBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [checkNumBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [checkNumBtn setBackgroundImage:[UIImage imageNamed:@"okay-button.png"] forState:UIControlStateNormal];
    [checkNumBtn setTitle:@"OK" forState:UIControlStateNormal];
    [checkPopUpPay addSubview:checkNumBtn];
    
    
 
}
-(void)EqualAmoutPaymetod
{
    double value=givenamout-amount;
    remainingamountstr = [NSString stringWithFormat:@"%.02f", value];

      [self payViewRemovingMethod];
    [PaypopupView removeFromSuperview];
    
    if (Myswitch.on)
    {
        if ([HoldID length]>0)
        {
            
            if ([SplitInvoiceID length]>0)
            {
                HoldStatus=@"complete";
                invoiceID=SplitInvoiceID;
                 paymentType=@"multiple";
                [self UpdateInVoiceDataMethod];
               // [self SaveInvoiceDataMethod];
                 split_amount=GivenAmountField.text;
                 payment_type=@"Cheque";
                [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                [self SaveSplitInvoiceMethod];
                  PrintSplitInvoiceID=SplitInvoiceID;
                [self SplitPrintStringMethod];
                SplitInvoiceID=@"";
                
            }
            else
            {
                 HoldStatus=@"complete";
                [self UpdateInVoiceDataMethod];
                
               
                 paymentType=@"Cheque";
               // [self SaveInvoiceDataMethod];
                
                [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                  TotalPaymetType=@"Cheque";
                [self EqualPrintStringMethod];
                
            }
           
            HoldID=@"";
            invoiceID=@"";
            
        }else{
            if ([SplitInvoiceID length]>0)
            {
                HoldStatus=@"complete";
                invoiceID=SplitInvoiceID;
                 paymentType=@"multiple";
                [self UpdateInVoiceDataMethod];
                //[self SaveInvoiceDataMethod];
                split_amount=GivenAmountField.text;
                
                 payment_type=@"Cheque";
                
                [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                [self SaveSplitInvoiceMethod];
                
                PrintSplitInvoiceID=SplitInvoiceID;
                  [self SplitPrintStringMethod];
                SplitInvoiceID=@"";
                
                
                
            }
            else
            {
                HoldStatus=@"complete";
                invoiceID=[generalDataObject  getDeviceID];
                 paymentType=@"Cheque";
                [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                [self SaveInvoiceDataMethod];
                    TotalPaymetType=@"Cheque";
                
                [self EqualPrintStringMethod];
             

                
                
            }
            
        }
        
    }
    
    if ([PrinterIpsArray count]>0)
    {
        [self PrinterDataMethod];        //[self GetPrint];
        
        
    }

  
    
    [ItemNamesArray removeAllObjects];
    [ItemNosArray removeAllObjects];
    [QntysArray removeAllObjects];
    [pricesArray removeAllObjects];
    [SnosArray removeAllObjects];
    [TaxesArray removeAllObjects];
    [AvegCostsArray removeAllObjects];
    [DiscountsArray removeAllObjects];
    
    [ItemVendorArray removeAllObjects];
    [ItemDeptsArray removeAllObjects];
    [ItemDesArray removeAllObjects];
    
    [ProductslistTable reloadData];
    SubTDisplaylbl.text=@"$ 0.00";
    taxDlbl.text=@"$ 0.00";
    GTotalDlbl.text=@"$ 0.00";
    
    
}
/*-(void)EqualPrintStringMethod
{
    stringToPrint = [[NSMutableString alloc] initWithString:@""];
    [stringToPrint appendFormat:@"Invoice#%@ \n\n Closed to Cash Purchase \n\n DATE/TIME:%@ \n \n CASHIER:1234 \n STATION:1 \n\n Item Count:%d \n=======================================\n",invoiceID,[generalDataObject getsystemDatetime],[ItemNamesArray count]];
    
    for(int i = 0;i<[ItemNamesArray count];i++)
    {
        
        NSString *name=[ItemNamesArray objectAtIndex:i];
        NSString *price=[pricesArray objectAtIndex:i];
        [stringToPrint appendFormat:@"%@\t\t$ %@",name,price];
        
        [stringToPrint appendFormat:@"\n"];
        
        
    }
    
    [stringToPrint appendFormat:@"\n======================================= \n\nSubtotal        %@ \nTax             %@ \nGrand Total     %@ \n%@            %@\nAmt Tendered    %@\nChange          $ %@\n\n Thank you for visiting\n\n\n",SubTotalstr,TaxValueStr,GrandTotalstr,TotalPaymetType,GrandTotalstr,GrandTotalstr,remainingamountstr];
    
    // //NSLog(@"Printing Data %@",stringToPrint);
    
    
}*/

+(UIImage *) imageFromWebView:(UIWebView *)view
{
    // tempframe to reset view size after image was created
    CGRect tmpFrame         = view.frame;
    
    // set new Frame
    CGRect aFrame               = view.frame;
    aFrame.size.height  = [view sizeThatFits:[[UIScreen mainScreen] bounds].size].height;
    view.frame              = aFrame;
    
    // do image magic
    UIGraphicsBeginImageContext([view sizeThatFits:[[UIScreen mainScreen] bounds].size]);
    
    CGContextRef resizedContext = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:resizedContext];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    // reset Frame of view to origin
    view.frame = tmpFrame;
    return image;
}
-(void)EqualPrintStringMethod
 {
  NSMutableString *stringToPrint = [[NSMutableString alloc] initWithString:@""];
     
     
     [stringToPrint appendFormat:@"<html><head><style type=\"text/css\">body {background-color:none;font-family : Verdana;color:#000000;font-size:28px;} table td {font-family : Verdana;color:#000000;font-size:28px; padding:0px 15px;} .tablehead{ font-size:32px;} </style><body style='background-color:none;'><center><table cellspacing=\"10\" width=';95%%' align='center' border=\"0\"><tr><th align=\"center\" colspan=\"2\">AonePOS</th></tr>"];
     
    
     
     [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Invoice#%@</span></th></tr>",invoiceID];
      [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Closed to Cash Purchase</span></th></tr>"];
    [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\"> DATE/TIME:%@</span></th></tr>",[generalDataObject getsystemDatetime]];
     
     [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\">CASHIER:1234</th></tr>"];
     [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"> STATION:1 </th></tr>"];
    [stringToPrint appendFormat:@"<tr><th align=\"left\" colspan=\"2\">Item Count:%d</th></tr>",[ItemNamesArray count]];
     
   [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\">=======================================</th></tr>"];
 for(int i = 0;i<[ItemNamesArray count];i++)
 {
    
 NSString *name=[ItemNamesArray objectAtIndex:i];
      NSString *price=[pricesArray objectAtIndex:i];
     [stringToPrint appendFormat:@"<tr><td align=\"left\"> %@ </td><td align=\"right\">$ %@<td><tr>",name,price];
     
 
 }
 
     [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\">=======================================</th></tr>"];
     
    [stringToPrint appendFormat:@"<tr><td align=\"left\"> Subtotal</td><td align=\"right\">%@<td><tr>",SubTotalstr];
    [stringToPrint appendFormat:@"<tr><td align=\"left\"> Grand Total</td><td align=\"right\">%@<td><tr>",TaxValueStr];
    [stringToPrint appendFormat:@"<tr><td align=\"left\"> Amt Tendered</td><td align=\"right\"> %@<td><tr>",GrandTotalstr];
     [stringToPrint appendFormat:@"<tr><td align=\"left\"> %@ </td><td align=\"right\">%@<td><tr>",TotalPaymetType,GrandTotalstr];
       [stringToPrint appendFormat:@"<tr><td align=\"left\"> Change</td><td align=\"right\">$ %@<td><tr>",remainingamountstr];
    [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\">Thank you for visiting</th></tr>"];
 
     [stringToPrint appendFormat:@"</table></center></body></html>"];
     
     
     [self printImageMethod:&stringToPrint];
     
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *documentsDirectory = [paths objectAtIndex:0];
     NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Print.txt"];

    [stringToPrint writeToFile:filePath atomically:TRUE encoding:NSUTF8StringEncoding error:NULL];
     
     stringToPrint=nil;
     
 }
-(void)printImageMethod:(NSString **)printstring
{
    UIWebView   *webView1 = [[UIWebView alloc] initWithFrame:CGRectMake(1069, 0, 600, 500)];
    
    [webView1 loadHTMLString:*printstring baseURL:nil];
    //webView1.hidden=YES;
    [webView1 setDelegate:self];
    [webView1 sizeToFit];
    //add to main view
    [self.view addSubview:webView1];
    //[self GetPrint:&webView1];
    
    printstring=nil;
   // [webView1 removeFromSuperview],[webView1 loadRequest:nil],webView1=nil;
}

-(void)SplitPrintStringMethod
{
 
 
    NSString *querySQL = [NSString stringWithFormat: @"SELECT payment_type,amount FROM split_invoice_table WHERE invoice_id='%@'",PrintSplitInvoiceID];
    NSMutableArray *splitinvArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:splitinvArray];
  
    
    NSMutableString *stringToPrint = [[NSMutableString alloc] initWithString:@""];

    [stringToPrint appendFormat:@"<html><head><style type=\"text/css\">body {background-color:none;font-family : Verdana;color:#000000;font-size:28px;} table td {font-family : Verdana;color:#000000;font-size:28px; padding:0px 15px;} .tablehead{ font-size:32px;} </style><body style='background-color:none;'><center><table cellspacing=\"10\" width=';95%%' align='center' border=\"0\"><tr><th align=\"center\" colspan=\"2\">AonePOS</th></tr>"];
    
    
    
    [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Invoice#%@</span></th></tr>",invoiceID];
      [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\">Closed to Cash Purchase</span></th></tr>"];
    [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"><span class=\"tablehead\"> DATE/TIME:%@</span></th></tr>",[generalDataObject getsystemDatetime]];
    
    [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\">CASHIER:1234</th></tr>"];
    [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\"> STATION:1 </th></tr>"];
    [stringToPrint appendFormat:@"<tr><th align=\"left\" colspan=\"2\">Item Count:%d</th></tr>",[ItemNamesArray count]];
    
    [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\">=======================================</th></tr>"];
    for(int i = 0;i<[ItemNamesArray count];i++)
    {
        
        NSString *name=[ItemNamesArray objectAtIndex:i];
        NSString *price=[pricesArray objectAtIndex:i];
        [stringToPrint appendFormat:@"<tr><td align=\"left\"> %@ </td><td align=\"right\">$ %@<td><tr>",name,price];
        
        
    }
    
    [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\">=======================================</th></tr>"];
    
    [stringToPrint appendFormat:@"<tr><td align=\"left\"> Subtotal</td><td align=\"right\">%@<td><tr>",SubTotalstr];
    [stringToPrint appendFormat:@"<tr><td align=\"left\"> Grand Total</td><td align=\"right\">%@<td><tr>",TaxValueStr];
    [stringToPrint appendFormat:@"<tr><td align=\"left\"> Amt Tendered</td><td align=\"right\"> %@<td><tr>",GrandTotalstr];
    [stringToPrint appendFormat:@"<tr><td align=\"left\"> Change</td><td align=\"right\">$ %@<td><tr>",remainingamountstr];
   

    NSMutableArray *paymentsArray,*amoutsArray;
    paymentsArray=[[NSMutableArray alloc]init];
    amoutsArray=[[NSMutableArray alloc]init];
    
    
    for (NSDictionary *myDict in splitinvArray)
    {
        
        [paymentsArray addObject:[myDict objectForKey:@"payment_type"]];
        [amoutsArray addObject:[myDict objectForKey:@"amount"]];
        
    }
    
    //NSString *mypaykey;
    int cashcount=0,checkcout=0,creditcount=0;
    
   // NSString *paymentstring;
    NSString *mypaymetstr=[[NSString alloc] init];
    NSString *CashAmt=@"0.00",*CheckAmt=@"0.00",*CreditAmt=@"0.00";
    
    for(int i = 0;i<[paymentsArray count];i++)
    {
        
       
        NSString *paytypekey=[paymentsArray objectAtIndex:i];
        
        NSString *paytype=[amoutsArray objectAtIndex:i];
        
       
        if ([paytypekey isEqualToString:@"Cash"])
        {
            
            if (cashcount>=1)
            {
                double payvalue=[mypaymetstr doubleValue];
                payvalue=payvalue+[paytype doubleValue];
                // //NSLog(@"pay amout %f",payvalue);
                mypaymetstr=[NSString stringWithFormat:@"%0.02f",payvalue];
                
            }
            else
            {
                
                mypaymetstr=paytype;
            }
            CashAmt=mypaymetstr;
            cashcount=cashcount+1;
            
        }
        if ([paytypekey isEqualToString:@"Cheque"])
        {
            
            if (checkcout>=1)
            {
                double payvalue=[mypaymetstr doubleValue];
                payvalue=payvalue+[paytype doubleValue];
                // //NSLog(@"pay amout %f",payvalue);
                mypaymetstr=[NSString stringWithFormat:@"%0.02f",payvalue];
                
            }
            else
            {
                
                mypaymetstr=paytype;
            }
            
          
            checkcout=checkcout+1;
            
            
            CheckAmt=mypaymetstr;
            
        }
        if ([paytypekey isEqualToString:@"Card"])
        {
            if (creditcount>=1)
            {
                double payvalue=[mypaymetstr doubleValue];
                payvalue=payvalue+[paytype doubleValue];
                // //NSLog(@"pay amout %f",payvalue);
                mypaymetstr=[NSString stringWithFormat:@"%0.02f",payvalue];
                
            }
            else
            {
                
                mypaymetstr=paytype;
            }
            CreditAmt=mypaymetstr;
            creditcount=creditcount+1;
        }
        
        // NSString *price=[pricesArray objectAtIndex:i];
        
    }
    
    
    [stringToPrint appendFormat:@"<tr><td align=\"left\"> Cash </td><td align=\"right\">$ %@<td><tr>",CashAmt];
    [stringToPrint appendFormat:@"<tr><td align=\"left\"> Cheque </td><td align=\"right\">$ %@<td><tr>",CheckAmt];
    [stringToPrint appendFormat:@"<tr><td align=\"left\"> Card </td><td align=\"right\">$ %@<td><tr>",CreditAmt];
    
    [stringToPrint appendFormat:@"<tr><th align=\"center\" colspan=\"2\">Thank you for visiting</th></tr>"];
    
    [stringToPrint appendFormat:@"</table></center></body></html>"];
    
    [self printImageMethod:&stringToPrint];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Print.txt"];
    
    [stringToPrint writeToFile:filePath atomically:TRUE encoding:NSUTF8StringEncoding error:NULL];
}
-(void)SplitpayMethod
{
    
    double value=amount-givenamout;
    remainingamountstr = [NSString stringWithFormat:@"%.02f", value];
    
    [AmountField setText:remainingamountstr];
    [GivenAmountField setText:remainingamountstr];
    
    //double splitamt=Grandvalue-value;
    float myFloat=[AmountField.text floatValue];
    
    int result = (int)roundf(myFloat);
    
    [(UIButton*)[PayView viewWithTag:105] setTitle:[NSString stringWithFormat:@"%d",result] forState:UIControlStateNormal];
    
    if (Myswitch.on)
    {
        if ([HoldID length]>0)
        {
        
            
            if ([SplitInvoiceID length]>0)
            {

                  invoice_id=SplitInvoiceID;
            
                
                  payment_type=[NSString stringWithFormat:@"%@",CashDropDown.titleLabel.text];
            
                   // //NSLog(@"the Amount in textfield is %@ %@", split_amount,payment_type);
            
                [self SaveSplitInvoiceMethod];
                [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                
                
            }
            else
            {
                
                SplitInvoiceID=invoiceID;
                invoice_id=SplitInvoiceID;
                
                //split_amount =[NSString stringWithFormat:@"%0.02f",splitamt];
                payment_type=[NSString stringWithFormat:@"%@",CashDropDown.titleLabel.text];
                
                // //NSLog(@"the Amount in textfield is %@ %@", split_amount,payment_type);
                
                HoldStatus=@"incomplete";
                paymentType=@"multiple";

                [self SaveSplitInvoiceMethod];
                [self UpdateInVoiceDataMethod];
               
                
               // [self SaveInvoiceDataMethod];
                [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                
                
            }
            
           
            //HoldID=@"";
            //invoiceID=@"";
            
        }
        else
        {
            HoldStatus=@"incomplete";
            if ([SplitInvoiceID length]>0){
                invoice_id=SplitInvoiceID;
                
                //split_amount =[NSString stringWithFormat:@"%0.02f",splitamt];
                payment_type=[NSString stringWithFormat:@"%@",CashDropDown.titleLabel.text];
                
                // //NSLog(@"the Amount in textfield is %@ %@", split_amount,payment_type);
                
                [self SaveSplitInvoiceMethod];
                
            }else{
                paymentType=@"multiple";
                SplitInvoiceID=[generalDataObject  getDeviceID];
                invoiceID=SplitInvoiceID;
                [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                [self SaveInvoiceDataMethod];
                
                invoice_id=SplitInvoiceID;
                
                //split_amount =[NSString stringWithFormat:@"%0.02f",splitamt];
                payment_type=[NSString stringWithFormat:@"%@",CashDropDown.titleLabel.text];
                
                // //NSLog(@"the Amount in textfield is %@ %@", split_amount,payment_type);
                
                [self SaveSplitInvoiceMethod];
                
            }
            
            
            
        }
        
    }
    
   
    
}


-(void)SaveSplitInvoiceMethod
{
    
    NSString * insertSQL;
    
    
    // NSString * payment_type , * amount, * check_no, * account_no, * invoice_id;
    insertSQL =@"insert into split_invoice_table (invoice_id, payment_type,amount,cheque_no,account_no,unique_id,created_timestamp,modified_timestamp,server_local) VALUES (?,?,?,?, ?,?,?,?,?)";
    NSMutableArray *splitArray=[[NSMutableArray alloc]initWithObjects:invoice_id, payment_type,split_amount,check_no,account_no,[generalDataObject  genRandStringLength:20],[generalDataObject getsystemDatetime],[generalDataObject getsystemDatetime],@"local", nil];
    [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertSQL withArguments:splitArray];
    
    
    NSString *querySQL = [NSString stringWithFormat: @"SELECT invoice_id, payment_type,amount,cheque_no,account_no,unique_id,created_timestamp,modified_timestamp,server_local FROM split_invoice_table WHERE invoice_id='%@'",invoice_id];
    NSMutableArray *splitinvoiceDataArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:splitinvoiceDataArray];
   
    
    SplitpaymentsArray=[[NSMutableArray alloc]init];
    splitAmoutsArray=[[NSMutableArray alloc]init];
    
    
    for (NSDictionary *myDict in splitinvoiceDataArray)
    {
        
        [SplitpaymentsArray addObject:[myDict objectForKey:@"payment_type"]];
        [splitAmoutsArray addObject:[myDict objectForKey:@"amount"]];
        
    }
    
    SplitInvoiceTable.hidden=NO;
    [SplitInvoiceTable reloadData];
  
    
    NSMutableDictionary *CategoryDict=[[NSMutableDictionary alloc]init];
    [CategoryDict setObject:splitArray forKey:@"fields"];
    NSDictionary *jsonDict = [NSDictionary dictionaryWithDictionary:CategoryDict];
    
    
    NSError *err;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:kNilOptions error:&err];
    
    NSString *str=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
    if(![generalDataObject  connectedToInternet])
    {
        NSString *insertSQL =@"insert into pending_queries (query_type,user_id,page_url,parameters,table_name,current_time) values(?,?,?,?,?,?)";
        NSMutableArray *pendingArray=[[NSMutableArray alloc]initWithObjects:@"INSERT",[generalDataObject  userID],@"saveinfo.php?",str,@"split_invoice_table",[generalDataObject getsystemDatetime], nil];
        
        [[DataBaseManager dataBaseManager] executeRecordsWithQuery:insertSQL withArguments:pendingArray];
        
    }
    else if([generalDataObject  connectedToInternet])
    {
        
        if ([[generalDataObject  OriginalbaseURLstr] length]>0)
        {
            
            // //NSLog(@"%@",str);
            NSString *string=[NSString stringWithFormat:@"%@saveinfo.php?tablename=split_invoice_table&systemtime=%@&userid=%@&sessionid=%@&data=%@",[generalDataObject  OriginalbaseURLstr],[[generalDataObject getsystemDatetime] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[generalDataObject  userID],[generalDataObject  deviceID],[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
            
            // //NSLog(@"%@",str);
            
            NSURL *url=[NSURL URLWithString:string];
            NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
            // //NSLog(@"%@",url);
            
            [request setHTTPMethod:@"POST"];
            [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
            //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
            
            
            
            InvoiceItemsConnection = [NSURLConnection connectionWithRequest:request delegate:self];
            
            [InvoiceItemsConnection start];
            
        }
        
    }
    
  check_no=@"";
    
    
    
}
-(void)CheckokBtnClick
{
    for (UILabel *lab in [checkPopUpPay subviews]) {
        [lab removeFromSuperview];
    }
    
    for (UITextField * tf in [checkPopUpPay subviews]) {
        [tf removeFromSuperview];
    }
    
    for (UIButton *but in [checkPopUpPay subviews]) {
        [but removeFromSuperview];
    }
    for (UIView *view in [checkPopUp subviews]) {
        [view removeFromSuperview];
    }
    [checkPopUp removeFromSuperview];
    check_no=checkNumTxt.text;
    InvoiceCheckNo=checkNumTxt.text;
    
    if (givenamout>=amount){
       
        [self EqualAmoutPaymetod];
        
    }else{
    
        [self SplitpayMethod];
    }
    
    //[checkPopUpPay removeFromSuperview];
    
}
-(void) payViewRemovingMethod
{
    
    
    NSArray *PaypopupViewArray = PaypopupView.subviews;
    for (int i = 0; i<[PaypopupViewArray count]; i++) {
        UIView *vi =[PaypopupViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *PayViewArray = PayView.subviews;
    for (int i = 0; i<[PayViewArray count]; i++) {
        UIView *vi =[PayViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [Quantityview removeFromSuperview],[PaypopupView removeFromSuperview];
    
}

-(void)Cancelpay
{
    [self payViewRemovingMethod];
   // [PaypopupView removeFromSuperview];
    
}
-(void)AmountClicked:(UIButton *)sender
{
  //  double value;
    
   
    // //NSLog(@"%@",sender.titleLabel.text);
    NSString *amoutstr=AmountField.text;
    amoutstr = [amoutstr stringByReplacingOccurrencesOfString:@"$ " withString:@""];
   amount=[amoutstr doubleValue];
   givenamout=[sender.titleLabel.text doubleValue];
      split_amount=[NSString stringWithFormat:@"%0.02f",givenamout];
    if (givenamout>=amount)
    {
        
        
        
        double value=givenamout-amount;
        remainingamountstr = [NSString stringWithFormat:@"%.02f", value];
        Changealert=[[UIAlertView alloc]initWithTitle:@"Remaining Change" message:[NSString stringWithFormat:@"%@%@",@"Change is  ",remainingamountstr] delegate:self
                                    cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
        
        [Changealert show];
          [self payViewRemovingMethod];
       
        
        if (Myswitch.on)
        {
            if ([HoldID length]>0)
            {
                
                if ([SplitInvoiceID length]>0)
                {
                    HoldStatus=@"complete";
                    paymentType=@"multiple";
                    invoiceID=SplitInvoiceID;
                    [self UpdateInVoiceDataMethod];
                    //[self SaveInvoiceDataMethod];
                    split_amount=GivenAmountField.text;
                    payment_type=[NSString stringWithFormat:@"%@",CashDropDown.titleLabel.text];
                    
                    [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                    [self SaveSplitInvoiceMethod];
                    PrintSplitInvoiceID=SplitInvoiceID;
                    [self SplitPrintStringMethod];
                    SplitInvoiceID=@"";
                    
                }
                else
                {
                      HoldStatus=@"complete";
                    [self UpdateInVoiceDataMethod];
                    
                  
                    paymentType=[NSString stringWithFormat:@"%@",CashDropDown.titleLabel.text];
                    //[self SaveInvoiceDataMethod];
                    
                    [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                    TotalPaymetType=@"Cash";
                    [self EqualPrintStringMethod];
                }
                
                HoldID=@"";
                invoiceID=@"";
                
            }
            else
            {
                if ([SplitInvoiceID length]>0)
                {
                    HoldStatus=@"complete";
                    paymentType=@"multiple";
                    invoiceID=SplitInvoiceID;
                    [self UpdateInVoiceDataMethod];
                   // [self SaveInvoiceDataMethod];
                    split_amount=GivenAmountField.text;
                    payment_type=[NSString stringWithFormat:@"%@",CashDropDown.titleLabel.text];
                    
                    [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                    [self SaveSplitInvoiceMethod];
                    PrintSplitInvoiceID=SplitInvoiceID;
                    [self SplitPrintStringMethod];
                    SplitInvoiceID=@"";
                    
                }
                else
                {
                    paymentType=[NSString stringWithFormat:@"%@",CashDropDown.titleLabel.text];
                    HoldStatus=@"complete";
                    invoiceID=[generalDataObject  getDeviceID];
                    
                    [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                    [self SaveInvoiceDataMethod];
                    
                    TotalPaymetType=@"Cash";
                    [self EqualPrintStringMethod];
                    
                    
                }
                
            }
            
        }
        
    
        
        [ItemNamesArray removeAllObjects];
        [ItemNosArray removeAllObjects];
        [QntysArray removeAllObjects];
        [pricesArray removeAllObjects];
        [SnosArray removeAllObjects];
        [TaxesArray removeAllObjects];
        [AvegCostsArray removeAllObjects];
        [DiscountsArray removeAllObjects];
        
        [ItemVendorArray removeAllObjects];
        [ItemDeptsArray removeAllObjects];
        [ItemDesArray removeAllObjects];
        
        [ProductslistTable reloadData];
        SubTDisplaylbl.text=@"$ 0.00";
        taxDlbl.text=@"$ 0.00";
        GTotalDlbl.text=@"$ 0.00";
        
    }
    else
    {
        [self SplitpayMethod];
        
        
    }
    
    
    
}
-(void)PrintertypeClicked
{
    if (PayPrinterDataTable.hidden==1)
    {
        
        PayPrinterDataTable.hidden=NO;
        
        
    }
    else if (PayPrinterDataTable.hidden==0)
    {
        
        [PayPrinterDataTable setHidden:YES];
        
    }
    
    
}
-(void)cashtypeClicked
{
    if (CashlistTable.hidden==1)
    {
        
        CashlistTable.hidden=NO;
        
        
    }
    else if (CashlistTable.hidden==0)
    {
        
        [CashlistTable setHidden:YES];
        
    }
}
-(void)UpdateStockInInventoryTableMethod
{
    NSMutableArray *productDataArray=[[NSMutableArray alloc]init];
    
    for (int i=0; i<[ItemNosArray count]; i++)
    {
        NSString *querySQL = [NSString stringWithFormat:@"SELECT inventory_item_no,inventary_in_stock FROM inventorytable WHERE inventory_item_no='%@' LIMIT 1",[ItemNosArray objectAtIndex:i]];
        NSMutableArray *indproductDataArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:indproductDataArray];
        [productDataArray addObjectsFromArray:indproductDataArray];
        [indproductDataArray removeAllObjects];
        indproductDataArray=nil;
    }
    
  
    NSMutableArray *mystockArray=[[NSMutableArray alloc]init];
    
    for (NSDictionary *myDict in productDataArray)
    {
        [mystockArray addObject:[myDict objectForKey:@"inventary_in_stock"]];
        
    }
   
     NSMutableArray *changestockArray=[[NSMutableArray alloc] init];
    for (int i=0; i<[mystockArray count]; i++)
    {
         double stockvalue=[[mystockArray objectAtIndex:i] doubleValue];
          double qty=[[QntysArray objectAtIndex:i] doubleValue];
        NSString *remainigStock=[NSString stringWithFormat:@"%0.02f",(stockvalue-qty)];
        
        [changestockArray addObject:remainigStock];
    }
   // // //NSLog(@"stocks %@",mystockArray);
    //// //NSLog(@"change stocks %@",changestockArray);
    for (int i=0; i<[changestockArray count]; i++)
    {
        NSString *stockstr=[changestockArray objectAtIndex:i];
        NSString *itemnoString=[ItemNosArray objectAtIndex:i];
        
          NSString *updateSQL = @"UPDATE inventorytable SET inventary_in_stock=? WHERE inventory_item_no=?";
        NSMutableArray *updateArray=[[NSMutableArray alloc]initWithObjects:stockstr,itemnoString, nil];
        [[DataBaseManager dataBaseManager]executeRecordsWithQuery:updateSQL withArguments:updateArray];
        
        NSString *querySQL = [NSString stringWithFormat:@"SELECT inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor,unique_id,created_timestamp,modified_timestamp,inventory_total_tax,inventary_notes,check_value,category_id,server_local FROM inventorytable WHERE inventory_item_no='%@'",itemnoString];
        NSMutableArray *productDataArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:productDataArray];
        
        NSMutableDictionary *CategoryDict=[[NSMutableDictionary alloc]init];
        [CategoryDict setObject:productDataArray forKey:@"fields"];
        NSDictionary *jsonDict = [NSDictionary dictionaryWithDictionary:CategoryDict];
        
        
        NSError *err;
        
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:kNilOptions error:&err];
        
        NSString *str=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        
        if(![generalDataObject  connectedToInternet]){
        
            NSString *insertSQL =@"insert into pending_queries (query_type,user_id,page_url,parameters,table_name,current_time) values(?,?,?,?,?,?)";
            NSMutableArray *pendingArray=[[NSMutableArray alloc]initWithObjects:@"UPDATE",[generalDataObject  userID],@"saveinfo.php?",str,@"inventorytable",[generalDataObject getsystemDatetime], nil];
            
            [[DataBaseManager dataBaseManager] executeRecordsWithQuery:insertSQL withArguments:pendingArray];
            
        }else if([generalDataObject  connectedToInternet]){
            
            
            if ([[generalDataObject  OriginalbaseURLstr] length]>0){
               // // //NSLog(@"%@",str);
                NSString *string=[NSString stringWithFormat:@"%@saveinfo.php?tablename=inventorytable&systemtime=%@&userid=%@&sessionid=%@&data=%@&update=true",[generalDataObject  OriginalbaseURLstr],[[generalDataObject getsystemDatetime] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[generalDataObject  userID],[generalDataObject  genRandStringLength:20],[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
                
                //// //NSLog(@"%@",str);
                
                NSURL *url=[NSURL URLWithString:string];
                NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
                //// //NSLog(@"%@",url);
                
                [request setHTTPMethod:@"POST"];
                [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
                //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
                
                
                
                InvoiceItemsConnection = [NSURLConnection connectionWithRequest:request delegate:self];
                
                [InvoiceItemsConnection start];
            }
        }
        
    }
    [mystockArray removeAllObjects],[changestockArray removeAllObjects],[productDataArray removeAllObjects];

}
-(void)SaveInvoiceDataMethod
{
    [self UpdateStockInInventoryTableMethod];

   // paymentType=[NSString stringWithFormat:@"%@",CashDropDown.titleLabel.text];
   
    
   // NSString *invoiceID=[generalDataObject  genRandStringLength:20];
    if ([[generalDataObject  userType]isEqualToString:@"employee"])
    {
        EmployeeID=[generalDataObject  userID];
    }
    //NSLog(@"%@",GrandTotalstr);
    double totlaprofit=SubtotalValue-TotalAvegCost;
    NSString *insertSQL;
    if ([ItemsArray count]>0)
    {
        for (int i=0; i<[ItemNosArray count]; i++)
        {
            NSString *ID=[ItemNosArray objectAtIndex:i];
             NSString *Discount=[DiscountsArray objectAtIndex:i];
             NSString *itemname=[ItemNamesArray objectAtIndex:i];
             NSString *des=[ItemDesArray objectAtIndex:i];
             NSString *price=[pricesArray objectAtIndex:i];
             NSString *avegcost=[AvegCostsArray objectAtIndex:i];
             NSString *Qty=[QntysArray objectAtIndex:i];
             NSString *Dept=[ItemDeptsArray objectAtIndex:i];
             NSString *Vendor=[ItemVendorArray objectAtIndex:i];
             NSString *Ttax=[TaxesArray objectAtIndex:i];
          
        
           insertSQL = @"insert into invoice_items_table (item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            
            NSMutableArray *invitemsArray=[[NSMutableArray alloc]initWithObjects:ID,Discount,Ttax,itemname,des,price,avegcost,Qty,invoiceID,[generalDataObject  genRandStringLength:20],[generalDataObject getsystemDatetime],paymentType,Dept,Vendor,StoreID,HoldStatus,EmployeeID,InVoiceCustomer, nil];
            [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertSQL withArguments:invitemsArray];
            
        }
    }
    
    
    NSString *querySQL = [NSString stringWithFormat: @"SELECT item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer FROM invoice_items_table WHERE invoice_id='%@'",invoiceID];
    NSMutableArray *invitemsArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:invitemsArray];
    
    querySQL=nil;
    
    NSMutableDictionary *CategoryDict=[[NSMutableDictionary alloc]init];
    [CategoryDict setObject:invitemsArray forKey:@"fields"];
    NSDictionary *jsonDict = [NSDictionary dictionaryWithDictionary:CategoryDict];
    
    
    NSError *err;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:kNilOptions error:&err];
    
    NSString *str=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
    if(![generalDataObject  connectedToInternet]){
    
        
        NSString *insertSQL =@"insert into pending_queries (query_type,user_id,page_url,parameters,table_name,current_time) values(?,?,?,?,?,?)";
        NSMutableArray *pendingArray=[[NSMutableArray alloc]initWithObjects:@"INSERT",[generalDataObject  userID],@"saveinfo.php?",str,@"invoice_items_table",[generalDataObject getsystemDatetime], nil];
        
        [[DataBaseManager dataBaseManager] executeRecordsWithQuery:insertSQL withArguments:pendingArray];
        
    }
    else if([generalDataObject  connectedToInternet])
    {
        
        if ([[generalDataObject  OriginalbaseURLstr] length]>0)
        {
        
       //// //NSLog(@"%@",str);
        NSString *string=[NSString stringWithFormat:@"%@saveinfo.php?tablename=invoice_items_table&systemtime=%@&userid=%@&sessionid=%@&data=%@",[generalDataObject  OriginalbaseURLstr],[[generalDataObject getsystemDatetime] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[generalDataObject  userID],[generalDataObject  deviceID],[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
       // // //NSLog(@"%@",str);
        
        NSURL *url=[NSURL URLWithString:string];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
       // // //NSLog(@"%@",url);
        
        [request setHTTPMethod:@"POST"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        
        
        
        InvoiceItemsConnection = [NSURLConnection connectionWithRequest:request delegate:self];
        
        [InvoiceItemsConnection start];
        }
    }

    
    
//Invoice total data
    
   
   
    NSString *Invoicesql;
    
    Invoicesql =@"insert into invoice_total_table (invoice_id,store_id,total_amt,status,payment_type,total_avgcost,total_profitt,unique_id,created_timestamp,holdid,employee,customer,cheque_no) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
    
    NSMutableArray *invtotalArray=[[NSMutableArray alloc]initWithObjects:invoiceID,StoreID,GrandTotalstr,HoldStatus,paymentType,TotalAvgStr,[NSString stringWithFormat:@"%.02f", totlaprofit],[generalDataObject  genRandStringLength:20],[generalDataObject getsystemDatetime],HoldID,EmployeeID,InVoiceCustomer,InvoiceCheckNo, nil];
    [[DataBaseManager dataBaseManager]executeRecordsWithQuery:Invoicesql withArguments:invtotalArray];

    
    
    NSString *querySQL2 = [NSString stringWithFormat: @"SELECT invoice_id,store_id,total_amt,status,payment_type,total_avgcost,total_profitt,unique_id,created_timestamp,holdid,employee,customer,cheque_no FROM invoice_total_table WHERE invoice_id='%@'",invoiceID];
    
    NSMutableArray *invtotalDataArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL2 resultsArray:invtotalDataArray];
    
    NSMutableDictionary *CategoryDict2=[[NSMutableDictionary alloc]init];
    [CategoryDict2 setObject:invtotalDataArray forKey:@"fields"];
    
    NSDictionary *jsonDict2 = [NSDictionary dictionaryWithDictionary:CategoryDict2];
    
    
    NSError *err2;
    
    NSData *jsonData2 = [NSJSONSerialization dataWithJSONObject:jsonDict2 options:kNilOptions error:&err2];
    
    NSString *str2=[[NSString alloc] initWithData:jsonData2 encoding:NSUTF8StringEncoding];
    
    if(![generalDataObject  connectedToInternet])
    {
       NSString *insertSQL =@"insert into pending_queries (query_type,user_id,page_url,parameters,table_name,current_time) values(?,?,?,?,?,?)";
        NSMutableArray *pendingArray=[[NSMutableArray alloc]initWithObjects:@"INSERT",[generalDataObject  userID],@"saveinfo.php?",str2,@"invoice_total_table",[generalDataObject getsystemDatetime], nil];
        
        [[DataBaseManager dataBaseManager] executeRecordsWithQuery:insertSQL withArguments:pendingArray];
        
    }
    else if([generalDataObject  connectedToInternet])
    {
        if ([[generalDataObject  OriginalbaseURLstr] length]>0)
        {
        
       // // //NSLog(@"%@",str2);
        NSString *string=[NSString stringWithFormat:@"%@saveinfo.php?tablename=invoice_total_table&systemtime=%@&userid=%@&sessionid=%@&data=%@",[generalDataObject  OriginalbaseURLstr],[[generalDataObject getsystemDatetime] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[generalDataObject  userID],[generalDataObject  deviceID],[str2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        
        
        NSURL *url=[NSURL URLWithString:string];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
       // // //NSLog(@"%@",url);
        
        [request setHTTPMethod:@"POST"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        
        
        
        InvoiceTotalConnection = [NSURLConnection connectionWithRequest:request delegate:self];
        
        [InvoiceTotalConnection start];
            
            
            
          
            
        }
    }
    
    CustomerNO=@"101";
    CustomerName=@"cashcustomer";
    CustomerPhoneNumber=@"";
    CusomerCompany=@"";
    
    InVoiceCustomer=CustomerNO;
    
    
    Customernamelbl.text=[NSString stringWithFormat:@"%@%@",@"Customer Name=",CustomerName];
    CustomerNolbl.text=[NSString stringWithFormat:@"%@%@",@"CustomerNumber=",CustomerNO];

    Customernamelbl.text=[NSString stringWithFormat:@"%@%@",@"Customer Company=",CusomerCompany];
    CustomerNolbl.text=[NSString stringWithFormat:@"%@%@",@"CustomerPhNo=",CustomerPhoneNumber];
    
   //InvoiceCheckNo=@"";
    invoiceID=@"";
    
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    
    if (connection == InvoiceItemsConnection){
        InvoiceItemData = [[NSMutableData alloc] init];
    }else if (connection == InvoiceTotalConnection){
        InvoiceTotalData = [[NSMutableData alloc] init];
    }
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    
    if (connection == InvoiceItemsConnection){
        [InvoiceItemData appendData:data];
    }else if (connection == InvoiceTotalConnection){
        [InvoiceTotalData appendData:data];
    }
   
    
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    if (connection == InvoiceItemsConnection){
        
        NSString *responseStr = [[NSString alloc] initWithBytes:[InvoiceItemData mutableBytes] length:[InvoiceItemData length] encoding:NSUTF8StringEncoding];
        
        NSError *error;
        NSMutableDictionary *dataDict;
        NSData *jsonData = [responseStr dataUsingEncoding:NSUTF8StringEncoding];
        dataDict =[NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
        // //NSLog(@"%@",dataDict);
        
        NSMutableArray *deleteArray=[dataDict objectForKey:@"delete-queries"];
        NSMutableArray *insertsArray=[dataDict objectForKey:@"insert-queries"];
        
        NSMutableArray *deletesArray;
        for (int i=0; i<[deleteArray count]; i++)
        {
            NSString *foo=[deleteArray objectAtIndex:i];
            NSString* bar = [foo stringByReplacingOccurrencesOfString:@"'" withString:@"\""];
            NSString* deletestr = [bar stringByReplacingOccurrencesOfString:@"\\\"" withString:@"'"];
            [[DataBaseManager dataBaseManager]executeRecordsWithQuery:deletestr withArguments:deletesArray];
            
            NSString *foo2=[insertsArray objectAtIndex:i];
            NSString* bar2 = [foo2 stringByReplacingOccurrencesOfString:@"'" withString:@"\""];
            NSString* insertstr = [bar2 stringByReplacingOccurrencesOfString:@"\\\"" withString:@"'"];
            
            [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertstr withArguments:deletesArray];
        }
      
    }else if (connection == InvoiceTotalConnection){
        
        NSString *responseStr = [[NSString alloc] initWithBytes:[InvoiceTotalData mutableBytes] length:[InvoiceTotalData length] encoding:NSUTF8StringEncoding];
        
        NSError *error;
        NSMutableDictionary *dataDict;
        NSData *jsonData = [responseStr dataUsingEncoding:NSUTF8StringEncoding];
        dataDict =[NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
        // //NSLog(@"%@",dataDict);
        
        
        NSMutableArray *deleteArray=[dataDict objectForKey:@"delete-queries"];
        NSMutableArray *insertsArray=[dataDict objectForKey:@"insert-queries"];
        
        NSMutableArray *deletesArray;
        for (int i=0; i<[deleteArray count]; i++)
        {
            NSString *foo=[deleteArray objectAtIndex:i];
            NSString* bar = [foo stringByReplacingOccurrencesOfString:@"'" withString:@"\""];
            NSString* deletestr = [bar stringByReplacingOccurrencesOfString:@"\\\"" withString:@"'"];
            [[DataBaseManager dataBaseManager]executeRecordsWithQuery:deletestr withArguments:deletesArray];
            
            NSString *foo2=[insertsArray objectAtIndex:i];
            NSString* bar2 = [foo2 stringByReplacingOccurrencesOfString:@"'" withString:@"\""];
            NSString* insertstr = [bar2 stringByReplacingOccurrencesOfString:@"\\\"" withString:@"'"];
            
            [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertstr withArguments:deletesArray];
        }
        
      
    }
}
-(void)SaveChangeQuantity
{
    [self qtyViewremoveMethod];
    
    if ([ChangeQuantityField .text length]>0)
    {
        
        
        NSString *price;
        
        NSString *item=[ItemsArray objectAtIndex:indexNO];
        
         NSString *querySQL = [NSString stringWithFormat: @"SELECT inventary_item_name,inventary_price_change FROM inventorytable WHERE inventary_item_name='%@'",item];
        NSMutableArray *productDataArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:productDataArray];
        
        for (NSDictionary *myDict in productDataArray)
        {
            NSString *itemstr=[myDict objectForKey:@"inventary_item_name"];
            if ([itemstr isEqualToString:item])
            {
                
                price=[myDict objectForKey:@"inventary_price_change"];
                
            }
        }
        
        [QntysArray removeObjectAtIndex:indexNO];
        [QntysArray insertObject:ChangeQuantityField.text atIndex:indexNO];
        
        //NSString *anotherprice=[pricesArray objectAtIndex:indexNO];
        
        Pricevalue=[ChangeQuantityField.text doubleValue]*[price doubleValue];
        [pricesArray removeObjectAtIndex:indexNO];
        
        [pricesArray insertObject:[NSString stringWithFormat:@"%0.02f",Pricevalue] atIndex:indexNO];
        
        [ProductslistTable reloadData];
        [self GetTotalAmountMethod];
       
        
    }
    else
    {
        //UIAlertView *itemalert=[[UIAlertView alloc]initWithTitle:@"Alert" message:@"Enter Quantity" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
        //[itemalert show];
        
          [self.view makeToast:@"Enter Quantity"];
    }
    itemselected=NO;
    
}
-(void)CancelChangeQuantity
{
   [self qtyViewremoveMethod];
    
}
-(void)QuantitybtnClikced
{
   
    if (RecallinvoiceValue==YES)
    {
        [Gobtn removeTarget:nil
                                action:NULL
                      forControlEvents:UIControlEventAllEvents];
    }
    else
    {
    
    if ([ProductscanField .text length]>0)
    {
        [retraiveOnHoldBtn setTitle:@"Save on Hold" forState:UIControlStateNormal];
        
        NSString *querySQL = [NSString stringWithFormat:@"SELECT inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor,inventory_total_tax FROM inventorytable"];
        NSMutableArray *productDataArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:productDataArray];
        
        NSMutableArray *myitemnumbersArray=[[NSMutableArray alloc]init];
        
        for (NSDictionary *myDict in productDataArray)
        {
            [myitemnumbersArray addObject:[myDict objectForKey:@"inventory_item_no"]];
        }
        
        
         NSUInteger objIdx = [myitemnumbersArray containsObject:ProductscanField.text];
        // //NSLog(@"%lu",(unsigned long)objIdx);
        if(objIdx == 0)
        {
            UIAlertView *itemalert=[[UIAlertView alloc]initWithTitle:@"Wrong" message:@"Wrong barcode" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
            [itemalert show];
        }
        else
        {
        for (NSDictionary *myDict in productDataArray)
        {
            NSString *itemstr=[myDict objectForKey:@"inventory_item_no"];
            if ([itemstr isEqualToString:ProductscanField.text])
            {
                NSString *itemno=[myDict objectForKey:@"inventory_item_no"];
                //NSString *Qty=[myDict objectForKey:@"inventary_quantity"];
                NSString *price=[myDict objectForKey:@"inventary_price_change"];
                
                
                
                if ([ItemNosArray count]>0)
                {
                    NSUInteger objIdx = [ItemNosArray containsObject:itemno];
                    // //NSLog(@"%lu",(unsigned long)objIdx);
                    if(objIdx == 0)
                    {
                        [ItemNosArray addObject:[myDict objectForKey:@"inventory_item_no"]];
                        [ItemNamesArray addObject:[myDict objectForKey:@"inventary_item_name"]];
                       
                      
                        [TaxesArray addObject:[myDict objectForKey:@"inventory_total_tax"]];
                        [AvegCostsArray addObject:[myDict objectForKey:@"inventary_avg_cost"]];
                        [DiscountsArray addObject:@"0"];
                        
                        [ItemVendorArray addObject:[myDict objectForKey:@"inventary_vendor"]];
                        [ItemDeptsArray addObject:[myDict objectForKey:@"inventary_department"]];
                        [ItemDesArray addObject:[myDict objectForKey:@"inventary_second_description"]];
                        [SnosArray addObject:[NSString stringWithFormat:@"%d",[ItemNamesArray count]]];
                        
                        if ([QantyField .text length]>0)
                        {
                            [QntysArray addObject:QantyField.text];
                            
                             Pricevalue=[QantyField.text doubleValue]*[price doubleValue];
                            [pricesArray addObject:[NSString stringWithFormat:@"%0.02f",Pricevalue]];
                        }
                        else
                        {
                            [QntysArray addObject:[myDict objectForKey:@"inventary_quantity"]];
                              [pricesArray addObject:[myDict objectForKey:@"inventary_price_change"]];
                        }
                    }
                    else
                    {
                        NSInteger qindex=[ItemNosArray indexOfObject:itemno];
                        //NSString *anotherqty=[QntysArray objectAtIndex:qindex];
                       // NSString *anotherprice=[pricesArray objectAtIndex:qindex];
                        
                        
                        
                        quantity=[QantyField.text intValue];
                        Pricevalue=Pricevalue=[QantyField.text doubleValue]*[price doubleValue];
                        
                        
                        [QntysArray removeObjectAtIndex:qindex];
                        [pricesArray removeObjectAtIndex:qindex];
                        [QntysArray insertObject:[NSString stringWithFormat:@"%d",quantity] atIndex:qindex];
                        [pricesArray insertObject:[NSString stringWithFormat:@"%0.02f",Pricevalue] atIndex:qindex];
                        
                        //[SnosArray addObject:[NSString stringWithFormat:@"%d",[ItemNamesArray count]]];
                    }
                }
                else
                {
                    
                    [ItemNosArray addObject:[myDict objectForKey:@"inventory_item_no"]];
                    [ItemNamesArray addObject:[myDict objectForKey:@"inventary_item_name"]];
                    [TaxesArray addObject:[myDict objectForKey:@"inventory_total_tax"]];
                    [AvegCostsArray addObject:[myDict objectForKey:@"inventary_avg_cost"]];
                    [DiscountsArray addObject:@"0"];
                    
                    [ItemVendorArray addObject:[myDict objectForKey:@"inventary_vendor"]];
                    [ItemDeptsArray addObject:[myDict objectForKey:@"inventary_department"]];
                    [ItemDesArray addObject:[myDict objectForKey:@"inventary_second_description"]];
                    [SnosArray addObject:[NSString stringWithFormat:@"%d",[ItemNosArray count]]];
                  
                    if ([QantyField .text length]>0)
                    {
                        [QntysArray addObject:QantyField.text];
                        
                        Pricevalue=[QantyField.text doubleValue]*[price doubleValue];
                        [pricesArray addObject:[NSString stringWithFormat:@"%0.02f",Pricevalue]];
                    }
                    else
                    {
                        [QntysArray addObject:[myDict objectForKey:@"inventary_quantity"]];
                        [pricesArray addObject:[myDict objectForKey:@"inventary_price_change"]];
                    }
                    
                }
                
                
                // //NSLog(@"%@",TaxesArray);
                
                
            }
        
        }
        
        
        // //NSLog(@"%@",ItemNamesArray);
        
        [ProductslistTable reloadData];
        [self GetTotalAmountMethod];
        
    }
    }
   if ([QantyField .text length]>0 && [ProductscanField.text length]==0)
   {
    if (itemselected)
    {
         // //NSLog(@"%d",indexNO);
        
        
        if ([QantyField .text length]>0)
        {
            NSString *price;
            
             NSString *item=[ItemsArray objectAtIndex:indexNO];
            NSString *querySQL = [NSString stringWithFormat:@"SELECT inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor FROM inventorytable"];
            NSMutableArray *productDataArray=[[NSMutableArray alloc]init];
            [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:productDataArray];
            for (NSDictionary *myDict in productDataArray)
            {
                NSString *itemstr=[myDict objectForKey:@"inventary_item_name"];
                if ([itemstr isEqualToString:item])
                {
                   
                    price=[myDict objectForKey:@"inventary_price_change"];
                    
                }
            }
            
            [QntysArray removeObjectAtIndex:indexNO];
            
            [QntysArray insertObject:QantyField.text atIndex:indexNO];
          
            
            //NSString *anotherprice=[pricesArray objectAtIndex:indexNO];
           
            Pricevalue=[QantyField.text doubleValue]*[price doubleValue];
            [pricesArray removeObjectAtIndex:indexNO];
            
            [pricesArray insertObject:[NSString stringWithFormat:@"%0.02f",Pricevalue] atIndex:indexNO];
            
            [ProductslistTable reloadData];
            
            [self GetTotalAmountMethod];
            
        }
        else
        {
            UIAlertView *itemalert=[[UIAlertView alloc]initWithTitle:@"Alert" message:@"Enter Quantity" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
            [itemalert show];
        }
        
    }
    else
    {
        // //NSLog(@"selected item");
       // UIAlertView *itemalert=[[UIAlertView alloc]initWithTitle:@"Alert" message:@"SelectItem" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
        //[itemalert show];
        
         [self.view makeToast:@"SelectItem."];
    }
  }
   ProductscanField.text=@"";
    QantyField.text=@"";
        itemselected=NO;
        
  }
}
-(void)CancelBtnClicked
{
  [ItemNumbersArray removeAllObjects],[ItemnameArray removeAllObjects], [productDesArray removeAllObjects],[priceyouchargeArray removeAllObjects],[InstockArray removeAllObjects],[VendorpartNosArray removeAllObjects];
    
    ItemNumbersArray=nil;
    ItemnameArray=nil;
    productDesArray=nil;
    SnosArray=nil;
    priceyouchargeArray=nil;
    InstockArray=nil;
    VendorpartNosArray=nil;
    [SearchlistTable removeFromSuperview];
    NSArray *SearchViewpopupArray = SearchView.subviews;
    for (int i = 0; i<[SearchViewpopupArray count]; i++) {
        UIView *vi =[SearchViewpopupArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *SearchViewArray = SearchViewpopup.subviews;
    for (int i = 0; i<[SearchViewArray count]; i++) {
        UIView *vi =[SearchViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [SearchView removeFromSuperview],[SearchViewpopup removeFromSuperview];
}
-(void)CategorySelectedBtn
{
    NSString *querySQL6 = [NSString stringWithFormat: @"SELECT category_id FROM category_details"];
    NSMutableArray *categorysArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL6 resultsArray:categorysArray];
    
    if (!categorynamesArray)
    categorynamesArray=[[NSMutableArray alloc]init];
    [categorynamesArray addObject:@"All"];
    for (NSDictionary *myDict in categorysArray)
    {
        
        NSString *catname=[myDict objectForKey:@"category_id"];
        [categorynamesArray addObject:catname];
        catname=nil;
        
    }
    if (!Pcategorypopup)
    Pcategorypopup=[[UIView alloc]init];
    if (isLandScope) {
        Pcategorypopup.frame=CGRectMake(0, 0, 1024, 768);
    }
    
    else{
        
        Pcategorypopup.frame=CGRectMake(0, 0, 768, 1024);
    }
    [Pcategorypopup setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:Pcategorypopup];
    if (!PCategorysTable)
    PCategorysTable=[[UITableView alloc]init];
    //[editProductTable  setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    [PCategorysTable setBackgroundColor:[UIColor whiteColor]];
    PCategorysTable.frame=CGRectMake(100,200 ,Pcategorypopup.frame.size.width-200, Pcategorypopup.frame.size.height-400);
    
    //editProductTable.contentSize = CGSizeMake(ProductView.frame.size.width+1000, ProductView.frame.size.height+1000);
    PCategorysTable.delegate=self;
    PCategorysTable.dataSource=self;
    
    [Pcategorypopup addSubview:PCategorysTable];
    
    
    
}

-(void)DepartmentSelectedBtn
{
    NSString *querySQL7 = [NSString stringWithFormat: @"SELECT department_id FROM department_details"];
    NSMutableArray *DeptsArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL7 resultsArray:DeptsArray];
    
    if (!DepartmentNamesArray)
    DepartmentNamesArray=[[NSMutableArray alloc]init];
    [DepartmentNamesArray addObject:@"All"];
    for (NSDictionary *myDict in DeptsArray)
    {
        
        NSString *catname=[myDict objectForKey:@"department_id"];
        [DepartmentNamesArray addObject:catname];
        catname=nil;
    }
      if (!Pdeaprtmentpopup)
    Pdeaprtmentpopup=[[UIView alloc]init];
    if (isLandScope) {
        Pdeaprtmentpopup.frame=CGRectMake(0, 0, 1024, 768);
    }
    
    else{
        
        Pdeaprtmentpopup.frame=CGRectMake(0, 0, 768, 1024);
    }
    [Pdeaprtmentpopup setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:Pdeaprtmentpopup];
    if (!PdepartmentsTable)
    PdepartmentsTable=[[UITableView alloc]init];
    //[editProductTable  setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    [PdepartmentsTable setBackgroundColor:[UIColor whiteColor]];
    PdepartmentsTable.frame=CGRectMake(100,200 ,Pdeaprtmentpopup.frame.size.width-200, Pdeaprtmentpopup.frame.size.height-400);
    
    //editProductTable.contentSize = CGSizeMake(ProductView.frame.size.width+1000, ProductView.frame.size.height+1000);
    PdepartmentsTable.delegate=self;
    PdepartmentsTable.dataSource=self;
    
    [Pdeaprtmentpopup addSubview:PdepartmentsTable];
    
    
}
-(void)CustomerGoBtnClicked
{
    if (![CustomerSearchField.text length]==0)
    {
         // NSString *querySQL = [NSString stringWithFormat: @"SELECT * FROM customer_table WHERE customer_no like'%%%@%%' OR customer_first_name like '%%%@%%'",CustomerSearchField.text,CustomerSearchField.text];
        
         NSString *querySQL = [NSString stringWithFormat: @"SELECT customer_no,customer_first_name,customer_last_name  FROM customer_table WHERE customer_no like'%%%@%%' ",CustomerSearchField.text];
    
        NSMutableArray *custArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:custArray];
        querySQL=nil;
        
        NSString *querySQL2 = [NSString stringWithFormat: @"SELECT shipping_phone,shipping_company_name FROM customer_shipping_table WHERE customer_no like'%%%@%%'",CustomerSearchField.text];
       
        NSMutableArray *custshpArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL2 resultsArray:custshpArray];
        
        querySQL2=nil;
        
        if ([custArray count]>0)
        {
             [self GetcustomerDatamethod];
              [CustomerlistTable reloadData];
        }
        else
        {
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"No results Available" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
            [alert show];
            alert=nil;
            
        }
        
    }
    if ([CustomerSearchField.text length]==0)
    {
        NSString *querySQL = [NSString stringWithFormat: @"SELECT customer_no,customer_first_name,customer_last_name FROM customer_table"];
        
        NSMutableArray *custArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:custArray];
        
        NSString *querySQL2 = [NSString stringWithFormat: @"SELECT shipping_phone,shipping_company_name FROM customer_shipping_table"];
        
        NSMutableArray *custshpArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL2 resultsArray:custshpArray];
        querySQL2=nil,querySQL=nil;
    
        if ([custArray count]>0)
        {
             [self GetcustomerDatamethod];
            [CustomerlistTable reloadData];
        }
    }
    
}
-(void)GoBtnClicked
{
    NSString *selectsql;
    NSString *CatID=[NSString stringWithFormat:@"%@",CatBtn.titleLabel.text];
    NSString *DeptID=[NSString stringWithFormat:@"%@",DeptBtn.titleLabel.text];
    
   
    if (![CatID isEqualToString:@"All"])
    {
        selectsql=[NSString stringWithFormat:@"SELECT  inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor,unique_id,created_timestamp,modified_timestamp,inventory_total_tax,inventary_notes,check_value,category_id FROM inventorytable WHERE category_id='%@'",[CatID stringByReplacingOccurrencesOfString:@" " withString:@""]];
        // //NSLog(@" seletced query %@",selectsql);
        
    }
    if(![DeptID isEqualToString:@"All"])
    {
        selectsql=[NSString stringWithFormat:@"SELECT inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor,unique_id,created_timestamp,modified_timestamp,inventory_total_tax,inventary_notes,check_value,category_id FROM inventorytable WHERE inventary_department='%@'",DeptID];
        // //NSLog(@" seletced query %@",selectsql);
        
    }
    if ([CatID isEqualToString:@"All"] && !([SearchField.text length]==0))
    {
        selectsql=[NSString stringWithFormat:@"SELECT  inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor,unique_id,created_timestamp,modified_timestamp,inventory_total_tax,inventary_notes,check_value,category_id FROM inventorytable WHERE inventory_item_no like'%%%@%%'OR inventary_item_name like '%%%@%%' ",SearchField.text,SearchField.text];
        // //NSLog(@" seletced query %@",selectsql);
        
    }
    if(!([SearchField.text length]==0) && [DeptID isEqualToString:@"All"])
    {
        selectsql=[NSString stringWithFormat:@"SELECT  inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor,unique_id,created_timestamp,modified_timestamp,inventory_total_tax,inventary_notes,check_value,category_id FROM inventorytable WHERE inventory_item_no like'%%%@%%'OR inventary_item_name like '%%%@%%' ",SearchField.text,SearchField.text];
        // //NSLog(@" seletced query %@",selectsql);
    }
     if(!([SearchField.text length]==0) && ![DeptID isEqualToString:@"All"])
    {
        selectsql=[NSString stringWithFormat:@"SELECT  inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor,unique_id,created_timestamp,modified_timestamp,inventory_total_tax,inventary_notes,check_value,category_id FROM inventorytable WHERE inventory_item_no like'%%%@%%'OR inventary_item_name like '%%%@%%'OR inventary_department='%@' ",SearchField.text,SearchField.text,DeptID];
        // //NSLog(@" seletced query %@",selectsql);
    }
     if(!([SearchField.text length]==0) && ![CatID isEqualToString:@"All"])
    {
        selectsql=[NSString stringWithFormat:@"SELECT  inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor,unique_id,created_timestamp,modified_timestamp,inventory_total_tax,inventary_notes,check_value,category_id FROM inventorytable WHERE inventory_item_no like'%%%@%%'OR inventary_item_name like '%%%@%%'OR category_id='%@' ",SearchField.text,SearchField.text,CatID];
        // //NSLog(@" seletced query %@",selectsql);
    }
    if (![CatID isEqualToString:@"All"]&&![DeptID isEqualToString:@"All"])
    {
        selectsql=[NSString stringWithFormat:@"SELECT  inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor,unique_id,created_timestamp,modified_timestamp,inventory_total_tax,inventary_notes,check_value,category_id FROM inventorytable WHERE inventary_department='%@' OR category_id='%@'",DeptID,CatID];
        // //NSLog(@" seletced query %@",selectsql);
    }
    
    if (![CatID isEqualToString:@"All"]&&![DeptID isEqualToString:@"All"]&& !([SearchField.text length]==0))
    {
        selectsql=[NSString stringWithFormat:@"SELECT  inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor,unique_id,created_timestamp,modified_timestamp,inventory_total_tax,inventary_notes,check_value,category_id FROM inventorytable WHERE inventory_item_no like'%%%@%%'OR inventary_item_name like '%%%@%%' OR inventary_department='%@' OR category_id='%@' ",SearchField.text,SearchField.text,DeptID,CatID];
        
    }
    if ([CatID isEqualToString:@"All"]&&[DeptID isEqualToString:@"All"]&& ([SearchField.text length]==0))
    {
        selectsql=[NSString stringWithFormat:@"SELECT  inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor,unique_id,created_timestamp,modified_timestamp,inventory_total_tax,inventary_notes,check_value,category_id FROM inventorytable"];
        
    }
    
    NSMutableArray *productDataArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:selectsql resultsArray:productDataArray];
  
    if ([productDataArray count]>0)
    {
        
        if(!ItemNumbersArray)
        ItemNumbersArray=[[NSMutableArray alloc]init];
        
        for (NSDictionary *myDict in productDataArray)
        {
            
            [ItemNumbersArray addObject:[myDict objectForKey:@"inventory_item_no"]];
            
        }
        if (!VendorpartNosArray)
        VendorpartNosArray=[[NSMutableArray alloc]init];
        NSString *querySQL2;
        
        if ([ItemNumbersArray count]>0){
           
            for (int i=0; i<[ItemNumbersArray count]; i++)
            {
                NSString *ProductNumber=[ItemNumbersArray objectAtIndex:i];
                querySQL2 = [NSString stringWithFormat: @"SELECT venderpart_no FROM ordering_info_table WHERE inventory_item_no='%@' AND preferred='%@'",ProductNumber,@"True"];
                
                NSMutableArray *vendorArray=[[NSMutableArray alloc]init];
                [[DataBaseManager dataBaseManager]execute:querySQL2 resultsArray:vendorArray];
                
                if ([vendorArray count]>0)
                {    NSDictionary *dict=[vendorArray objectAtIndex:0];
                    [VendorpartNosArray addObject:[dict objectForKey:@"venderpart_no"]];
                }
                else
                {
                    [VendorpartNosArray addObject:@""];
                }
            }
            
        }
        [SearchlistTable reloadData];
    }
    else
    {
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"No results Available" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
        [alert show];
        
        alert=nil;
    }
    selectsql=nil,DeptID=nil,CatID=nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
   
    if (tableView==SearchlistTable )
    {
        if (indexPath.row==0)
        {
            
            return 60;
        }else{
           
            return 80;
        }
    }else if (tableView==ProductslistTable)
    {
    
            
            NSString *cellText    = [ItemNamesArray objectAtIndex:0];
            UIFont *cellFont      = [UIFont fontWithName:@"Helvetica-neuve" size:21.0];
            CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
            CGSize labelSize      = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:NSLineBreakByWordWrapping];
            int buffer  = 70;
            
            return labelSize.height + buffer;
        
    }else if (tableView==DepartmentsTable){
        return 39;
    }else if (tableView==FecthOnHoldlistTable){
        if (indexPath.row==0)
        {
            
            return 60;
        }else{
            
            return 80;
        }
        
    }else if (tableView==RecallListTable){
        return 60;
    }else{
        return 50;
        
    }
   
    return YES;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    // This will create a "invisible" footer
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
    
    // If you are not using ARC:
    // return [[UIView new] autorelease];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView==DepartmentsTable)
    {
        return [departmentsArray count];
    }else if (tableView==ProductslistTable){
        
        return [ItemNamesArray count];
    }else if (tableView==SearchlistTable)
    {
        return [ItemNumbersArray count]+1;
    }else if (tableView == PCategorysTable)
    {
        return [categorynamesArray count];
        
    }else if (tableView == PdepartmentsTable){
        return [DepartmentNamesArray count];
    }else if (tableView== ItemsDataTable){
        return [SearchDataArray count];
    }else if (tableView== CashlistTable){
        return [paytypesArray count];
    }else if (tableView==CustomerlistTable){
        return [CustomerNosArray count]+1;
    }else  if (tableView==CustomerDataTable){
        return [CustomerDataArray count];
        
    }else if (tableView==FecthOnHoldlistTable){
        
        return [InVoiceIdsArray count];
        
    }else if (tableView==ProductPrintertable){
        return [ProductNamesArray count]+1;
    }else if (tableView==MinitsTable){
        return [MinitsArray count];
    }else if (tableView==PrinterNamesTable){
        return [PrinterNamesArray count];
    }else if (tableView==StoresListTable){
        return [StoresArray count];
    }else if (tableView==PayPrinterDataTable){
        return [PrinterIpsArray count];
    }else if (tableView==RecallListTable){
        return [InVoiceIdsArray count];
    }else if (tableView==DisTableview){
        return [DiscsArray count];
    }else if (tableView==SplitDataTable){
        return [SplitNamesArray count];
    }else if (tableView==SplitInvoiceTable){
        return [SplitpaymentsArray count]+1;
    }
       // [SplitDataTable reloadData];
    
    return YES;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (tableView==SearchlistTable){
        
            
            HomeSearchCell  *cell = (HomeSearchCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
            
            if(!cell) {
                [[NSBundle mainBundle] loadNibNamed:@"HomeSearchCell" owner:self options:nil];
                cell = homeSearchCell;
            }
            
            // // //NSLog(@"Dict :-%@",dict);
            if (indexPath.row==0){
                 cell.sNo_TextView.text = @"S.No";
                cell.itemNo_TextView.text = @"ItemNo";
                cell.itemName_TextView.text =@"ItemName";
                cell.price_TextView.text =@"Price";
                cell.stock_TextView.text =@"Stock";
                cell.discount_TextView.text =@"Des2";
                cell.vendorPartNo_TextView.text =@"Vendor";
                
                cell.sNo_TextView.textColor=[UIColor whiteColor];
                cell.itemNo_TextView.textColor=[UIColor whiteColor];
                cell.itemName_TextView.textColor=[UIColor whiteColor];
                cell.price_TextView.textColor=[UIColor whiteColor];
                cell.stock_TextView.textColor=[UIColor whiteColor];
                cell.discount_TextView.textColor=[UIColor whiteColor];
                cell.vendorPartNo_TextView.textColor=[UIColor whiteColor];
                cell.contentView.backgroundColor=[UIColor blackColor];
              
                
            }else{
                cell.sNo_TextView.text = [SnosArray objectAtIndex:indexPath.row];
                cell.itemNo_TextView.text =[ItemNumbersArray objectAtIndex:indexPath.row];
                cell.itemName_TextView.text =[ItemnameArray objectAtIndex:indexPath.row];
                cell.price_TextView.text =[priceyouchargeArray objectAtIndex:indexPath.row];
                cell.stock_TextView.text =[InstockArray objectAtIndex:indexPath.row];
                cell.discount_TextView.text =[productDesArray objectAtIndex:indexPath.row];
                cell.vendorPartNo_TextView.text =[VendorpartNosArray objectAtIndex:indexPath.row];
                
               
                cell.sNo_TextView.textColor=[UIColor blackColor];
                cell.itemNo_TextView.textColor=[UIColor blackColor];
                cell.itemName_TextView.textColor=[UIColor blackColor];
                cell.price_TextView.textColor=[UIColor blackColor];
                cell.stock_TextView.textColor=[UIColor blackColor];
                cell.discount_TextView.textColor=[UIColor blackColor];
                cell.vendorPartNo_TextView.textColor=[UIColor blackColor];

                cell.contentView.backgroundColor=[UIColor whiteColor];
                cell.accessoryType=UITableViewCellAccessoryCheckmark;

            }
            return cell;
        
        
    }else if (tableView==RecallListTable){
        
        
        RecallInvoiceCell  *cell = (RecallInvoiceCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
        
        if(!cell) {
            [[NSBundle mainBundle] loadNibNamed:@"RecallInvoiceCell" owner:self options:nil];
            cell = recallInvoiceCell;
        }
        
        // // //NSLog(@"Dict :-%@",dict);
        if (indexPath.row==0){
            cell.sNo_TextView.text = @"S.No";
            cell.invoiceID_TextView.text = @"InvoiceId";
            cell.payType_TextView.text =@"PayType";
            cell.totalAmt_TextView.text =@"TotalAmt";
            cell.dateTime_TextView.text =@"Date&Time";
          
            
            cell.sNo_TextView.textColor=[UIColor whiteColor];
            cell.invoiceID_TextView.textColor=[UIColor whiteColor];
            cell.payType_TextView.textColor=[UIColor whiteColor];
            cell.totalAmt_TextView.textColor=[UIColor whiteColor];
            cell.dateTime_TextView.textColor=[UIColor whiteColor];
           
            cell.contentView.backgroundColor=[UIColor blackColor];
            
            
        }else{
            
            
            //// //NSLog(@"Dict _%@",dict);
            cell.sNo_TextView.text = [RsonsArray objectAtIndex:indexPath.row-1];
            cell.invoiceID_TextView.text =[InVoiceIdsArray objectAtIndex:indexPath.row];
            cell.payType_TextView.text =[paymentTypesArray objectAtIndex:indexPath.row];
            cell.totalAmt_TextView.text =[TotalAmountsArray objectAtIndex:indexPath.row];
            cell.dateTime_TextView.text =[TimesArray objectAtIndex:indexPath.row];
          
            
            
            cell.sNo_TextView.textColor=[UIColor blackColor];
            cell.invoiceID_TextView.textColor=[UIColor blackColor];
            cell.payType_TextView.textColor=[UIColor blackColor];
            cell.totalAmt_TextView.textColor=[UIColor blackColor];
            cell.dateTime_TextView.textColor=[UIColor blackColor];
          
            
            cell.contentView.backgroundColor=[UIColor whiteColor];
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            
        }
        return cell;
        
        
    }else if (tableView==FecthOnHoldlistTable){
        
        
        FetchonHoldCell  *cell = (FetchonHoldCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
        
        if(!cell) {
            [[NSBundle mainBundle] loadNibNamed:@"FetchonHoldCell" owner:self options:nil];
            cell = fetchonHoldCell;
        }
     
            cell.holdId_TextView.text = [HoldIdsArray objectAtIndex:indexPath.row];
            cell.invoiceID_TextView.text =[InVoiceIdsArray objectAtIndex:indexPath.row];
            cell.time_TextView.text =[TimesArray objectAtIndex:indexPath.row];
            cell.totalAmt_TextView.text =[TotalAmountsArray objectAtIndex:indexPath.row];
            cell.employee_TextView.text =[EmployeesArray objectAtIndex:indexPath.row];
        
            cell.contentView.backgroundColor=[UIColor whiteColor];
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        cell.edit_Button.tag=indexPath.row;
        cell.delete_Button.tag=indexPath.row;
       
        return cell;
        
        
    }else if (tableView==SplitInvoiceTable){
        
        if (!SnosArray)
        SnosArray=[[NSMutableArray alloc]init];
        for (int i=1;i<=[SplitpaymentsArray count] ; i++)
        {
            [SnosArray  addObject:[NSString stringWithFormat:@"%d",i]];
            
        }
        SplitInvoiceCell  *cell = (SplitInvoiceCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
        
        if(!cell) {
            [[NSBundle mainBundle] loadNibNamed:@"SplitInvoiceCell" owner:self options:nil];
            cell = splitInvoiceCell;
        }
        
        // // //NSLog(@"Dict :-%@",dict);
        if (indexPath.row==0){
            
            cell.sno_Label.text = @"S.No";
            cell.payType_Label.text = @"Paytype";
            cell.Amount_Label.text =@"Amount";
        
            cell.sno_Label.textColor=[UIColor whiteColor];
            cell.payType_Label.textColor=[UIColor whiteColor];
            cell.Amount_Label.textColor=[UIColor whiteColor];
        
            cell.contentView.backgroundColor=[UIColor blackColor];
            
            
        }else{
            
            cell.sno_Label.text = [SnosArray objectAtIndex:indexPath.row-1];
            cell.payType_Label.text =[SplitpaymentsArray objectAtIndex:indexPath.row-1];
            cell.Amount_Label.text =[splitAmoutsArray objectAtIndex:indexPath.row-1];
        
            cell.sno_Label.textColor=[UIColor blackColor];
            cell.payType_Label.textColor=[UIColor blackColor];
            cell.Amount_Label.textColor=[UIColor blackColor];
    
            cell.contentView.backgroundColor=[UIColor whiteColor];
            //cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            
        }
        return cell;
        
        
    }else if (tableView==CustomerlistTable){
        
        
        HomeCustomerCell  *cell = (HomeCustomerCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
        
        if(!cell) {
            [[NSBundle mainBundle] loadNibNamed:@"HomeCustomerCell" owner:self options:nil];
            cell = homeCustomerCell;
        }
        
        // // //NSLog(@"Dict :-%@",dict);
        if (indexPath.row==0){
            cell.sno_TextView.text = @"S.No";
            cell.customer_TextView.text = @"Customer";
            cell.firstName_TextView.text =@"FirstName";
            cell.lastName_TextView.text =@"LastName";
            cell.company_TextView.text =@"Company";
            cell.phone_TextView.text =@"Phone";
            
            
            cell.sno_TextView.textColor=[UIColor whiteColor];
            cell.customer_TextView.textColor=[UIColor whiteColor];
            cell.firstName_TextView.textColor=[UIColor whiteColor];
            cell.lastName_TextView.textColor=[UIColor whiteColor];
            cell.company_TextView.textColor=[UIColor whiteColor];
            cell.phone_TextView.textColor=[UIColor whiteColor];
            cell.contentView.backgroundColor=[UIColor blackColor];
            
            
        }else{
            
            
            //// //NSLog(@"Dict _%@",dict);
            cell.sno_TextView.text = [CuSnosArray objectAtIndex:indexPath.row-1];
            cell.customer_TextView.text =[CustomerNosArray objectAtIndex:indexPath.row-1];
            cell.firstName_TextView.text =[CuFirstnamesArray objectAtIndex:indexPath.row-1];
            cell.lastName_TextView.text =[CuLastnamesArray objectAtIndex:indexPath.row-1];
            cell.company_TextView.text =[ShCompanynamesArray objectAtIndex:indexPath.row-1];
            cell.phone_TextView.text =[ShPhonenumbersArray objectAtIndex:indexPath.row-1];
            
            
            cell.sno_TextView.textColor=[UIColor blackColor];
            cell.customer_TextView.textColor=[UIColor blackColor];
            cell.firstName_TextView.textColor=[UIColor blackColor];
            cell.lastName_TextView.textColor=[UIColor blackColor];
            cell.company_TextView.textColor=[UIColor blackColor];
            cell.phone_TextView.textColor=[UIColor blackColor];
            
            cell.contentView.backgroundColor=[UIColor whiteColor];
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            
        }
        return cell;
        
        
    }else if (tableView==ProductslistTable){
       // if(!SnosArray)
        SnosArray=[[NSMutableArray alloc]init];
        for (int i=1;i<=[ItemNamesArray count] ; i++)
        {
            [SnosArray  addObject:[NSString stringWithFormat:@"%d",i]];
            
        }
        HomeProductListCell  *cell = (HomeProductListCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
        
        if(!cell) {
            [[NSBundle mainBundle] loadNibNamed:@"HomeProductListCell" owner:self options:nil];
            cell = homeProductListCell;
        }
        
        // // //NSLog(@"Dict :-%@",dict)
        
        //// //NSLog(@"Dict _%@",dict);
        cell.sno_TextView.text = [SnosArray objectAtIndex:indexPath.row];
        cell.item_TextView.text =[ItemNosArray objectAtIndex:indexPath.row];
        cell.iteminfo_TextView.text =[ItemNamesArray objectAtIndex:indexPath.row];
        cell.qty_TextView.text =[QntysArray objectAtIndex:indexPath.row];
        cell.price_TextView.text =[pricesArray objectAtIndex:indexPath.row];
        
        cell.contentView.backgroundColor=[UIColor whiteColor];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        
        cell.delete_Button.tag=indexPath.row;
        
        return cell;
      
    }else{
        static NSString *CellIdentifier = @"Cell";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        
        if(!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
        }
    
    if (tableView==DisTableview)
    {
        cell.textLabel.text=[DiscsArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }else if (tableView==PayPrinterDataTable){
        cell.textLabel.text=[PrinterIpsArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }else if (tableView==StoresListTable){
        cell.textLabel.text=[StoresArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }else if (tableView==MinitsTable){
        cell.textLabel.text=[MinitsArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }else if (tableView == PrinterNamesTable){
        cell.textLabel.text=[PrinterNamesArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
        
    }else if (tableView==CustomerDataTable){
        cell.textLabel.text=[CustomerDataArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }else if (tableView == PCategorysTable){
        cell.textLabel.text=[categorynamesArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
        
    }else if (tableView == CashlistTable){
        cell.textLabel.text=[paytypesArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
        
    }else if (tableView == PdepartmentsTable){
        cell.textLabel.text=[DepartmentNamesArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
       
        
    }else if (tableView==DepartmentsTable){
        cell.textLabel.text=[departmentsArray objectAtIndex:indexPath.row];
        cell.textLabel.backgroundColor=[UIColor clearColor];
        
      
        cell.selected=0;
        cell.backgroundColor=[UIColor colorWithRed:60.0f/255.0f green:101.0f/255.0f blue:134.0f/255.0f alpha:1.0f];
       //UIImage *cellBackgroundNormal = [UIImage imageNamed:@"departmentselectedhightlighted.png"];
        UIImage *cellBackgroundSelected = [UIImage imageNamed:@"departmentselectedhightlighted.png"];
       //UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:cellBackgroundNormal];
        UIImageView *cellBackgroundSelectedView = [[UIImageView alloc] initWithImage:cellBackgroundSelected];
        //cell.backgroundView = cellBackgroundView;
        cell.selectedBackgroundView = cellBackgroundSelectedView;
      
        cell.textLabel.highlightedTextColor = [UIColor blackColor];
    
          cell.textLabel.textColor=[UIColor whiteColor];
        
    }else if (tableView== ProductPrintertable){
        if (indexPath.row==0)
        {
            
            UITextView  *namelbl2;
            if (!namelbl2)
            namelbl2=[[UITextView alloc] initWithFrame:CGRectMake(10, 0, 150, 40)];
            [namelbl2 setBackgroundColor:[UIColor clearColor]];
            [namelbl2 setTextColor:[UIColor blackColor]];
            namelbl2.editable=NO;
            [namelbl2 setTextAlignment:NSTextAlignmentLeft];
            [namelbl2 setFont:[UIFont systemFontOfSize:20.0f]];
            [namelbl2 setText:@"Product"];
            [cell.contentView addSubview:namelbl2];
            UITextView  *taxlbl2;
             if (!taxlbl2)
            taxlbl2=[[UITextView alloc] initWithFrame:CGRectMake(150, 0, 150, 40)];
            [taxlbl2 setBackgroundColor:[UIColor clearColor]];
            [taxlbl2 setTextColor:[UIColor blackColor]];
            [taxlbl2 setFont:[UIFont systemFontOfSize:20.0f]];
            taxlbl2.editable=NO;
            [taxlbl2 setTextAlignment:NSTextAlignmentLeft];
            [taxlbl2 setText:@"Printer"];
            [cell.contentView addSubview:taxlbl2];
            
            UITextView  *pricelbl2;
             if (!pricelbl2)
            pricelbl2=[[UITextView alloc] initWithFrame:CGRectMake(320, 0, 150, 40)];
            [pricelbl2 setBackgroundColor:[UIColor clearColor]];
            [pricelbl2 setTextColor:[UIColor blackColor]];
            pricelbl2.editable=NO;
            [pricelbl2 setTextAlignment:NSTextAlignmentLeft];
            [pricelbl2 setFont:[UIFont systemFontOfSize:20.0f]];
            [pricelbl2 setText:@"Time"];
            [cell.contentView addSubview:pricelbl2];
            
            UITextView  *stock2;
             if (!stock2)
            stock2=[[UITextView alloc] initWithFrame:CGRectMake(490, 0, 150, 40)];
            [stock2 setBackgroundColor:[UIColor clearColor]];
            [stock2 setTextColor:[UIColor blackColor]];
            [stock2 setFont:[UIFont systemFontOfSize:20.0f]];
            stock2.editable=NO;
            [stock2 setTextAlignment:NSTextAlignmentLeft];
            [stock2 setText:@"Message"];
            [cell.contentView addSubview:stock2];
          cell.contentView.backgroundColor=[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f];
            
            
        }
        else
        {
            UITextView  *namelbl2;
            if (!namelbl2)
            namelbl2=[[UITextView alloc] initWithFrame:CGRectMake(10, 0, 150, 40)];
            [namelbl2 setBackgroundColor:[UIColor clearColor]];
            [namelbl2 setTextColor:[UIColor blackColor]];
            namelbl2.editable=NO;
            [namelbl2 setTextAlignment:NSTextAlignmentLeft];
            [namelbl2 setFont:[UIFont systemFontOfSize:20.0f]];
            [namelbl2 setText:[ProductNamesArray objectAtIndex:indexPath.row-1]];
            [cell.contentView addSubview:namelbl2];
            
            if (!PrinterBtn)
            PrinterBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            [PrinterBtn setFrame:CGRectMake(150, 5, 150, 30)];
             // [PrinterBtn setImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
            [PrinterBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [PrinterBtn setTitle:[DepPrinterDataArray objectAtIndex:indexPath.row-1] forState:UIControlStateNormal];
            [PrinterBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
          
            [PrinterBtn addTarget:self action:@selector(PrinterName:) forControlEvents:UIControlEventTouchUpInside];
            PrinterBtn.tag=indexPath.row-1;
            [cell.contentView addSubview:PrinterBtn];
            if (!TimeBtn)
            TimeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            [TimeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [TimeBtn setTitle:[DepTimesArray objectAtIndex:indexPath.row-1] forState:UIControlStateNormal];
           [TimeBtn setFrame:CGRectMake(320, 5, 150,30)];
            [TimeBtn addTarget:self action:@selector(TimeBtn:) forControlEvents:UIControlEventTouchUpInside];
            [TimeBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
            TimeBtn.tag=indexPath.row-1;
            [cell.contentView addSubview:TimeBtn];
            
            if (!ProductTextView)
            ProductTextView = [[UITextField alloc]initWithFrame:CGRectMake(490,5, 220, 30)];
            //printerCharTF.borderStyle = UITextBorderStyleRoundedRect;
            ProductTextView.text=[QtyitemsArry objectAtIndex:indexPath.row-1];
            ProductTextView.delegate=self;
            ProductTextView.tag=indexPath.row-1;
            [ProductTextView setTextColor:[UIColor blackColor]];
            [ProductTextView addTarget:self action:@selector(textFiledDidChange:) forControlEvents:UIControlEventEditingDidEnd];
            [ProductTextView setBackground:[UIImage imageNamed:@"additionaloptions.png"]];
           // [ProductTextView setBackgroundColor:[UIImage imageNamed:@"additionaloptions.png"]];
            [cell.contentView addSubview:ProductTextView];
            
            
            if (indexPath.row%2==0)
            {
                
                cell.contentView.backgroundColor=[UIColor colorWithRed:64.0f/255.0f green:96.0f/255.0f blue:120.0f/255.0f alpha:1.0f];
            }
            else
                
            {
                cell.contentView.backgroundColor=[UIColor colorWithRed:56.0f/255.0f green:104.0f/255.0f blue:128.0f/255.0f alpha:1.0f];
                
            }
        }
        
        
        
    }else if (tableView== ItemsDataTable){
        cell.textLabel.text=[SearchDataArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
        
    }
    
    
  [self updateUI];
    
    
    return cell;
    }
    

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==DisTableview)
    {
        //[StoresPopupView removeFromSuperview];
        DisTableview.hidden=YES;
        
        NSString *selectedstr=[DiscsArray objectAtIndex:indexPath.row];
        [DisDropdownBtn setTitle:selectedstr forState:UIControlStateNormal];
        selectedstr=nil;
        [DiscsArray removeAllObjects];
        DiscsArray=nil;
        
    }else if (tableView==DepartmentsTable){
       [ItemsArray removeAllObjects];
       ItemsArray=nil;
        ItemsArray=[[NSMutableArray alloc]init];
            NSString *selectedstr=[departmentsArray objectAtIndex:indexPath.row];
        
        [self departmentselected:selectedstr];
        ////NSLog(@"%@",selectedstr);
       // selectedstr=nil;
        
    }else if (tableView==StoresListTable){
        //[StoresPopupView removeFromSuperview];
        StoresListTable.hidden=YES;
        
        NSString *selectedstr=[StoresArray objectAtIndex:indexPath.row];
        [SelectStoreBtn setTitle:selectedstr forState:UIControlStateNormal];
        selectedstr=nil;
        
    }else if (tableView==PayPrinterDataTable){
        //[StoresPopupView removeFromSuperview];
        PayPrinterDataTable.hidden=YES;
        
        NSString *selectedstr=[PrinterIpsArray objectAtIndex:indexPath.row];
        [SelectPrinterBtn setTitle:selectedstr forState:UIControlStateNormal];
          selectedstr=nil;
        PayPrinterName=[printernamesArray objectAtIndex:indexPath.row];
        
        printChar=[printcharArray objectAtIndex:indexPath.row];
        
        font=[FontsArray objectAtIndex:indexPath.row];
      align=[AlignsArray objectAtIndex:indexPath.row];
        language=[languagesArray objectAtIndex:indexPath.row];
       Pwidth=[WidthsArray objectAtIndex:indexPath.row];
       Pheight=[HeightsArray objectAtIndex:indexPath.row];
        
        Bold=[boldsArray objectAtIndex:indexPath.row];
        Underline=[UnderlinesArray objectAtIndex:indexPath.row];
        
       xposition =[XpossArray objectAtIndex:indexPath.row];
       spacing=[spacingsArray objectAtIndex:indexPath.row];
       
       Ipadd=[IpAddsArray objectAtIndex:indexPath.row];
       
        unit=[unitsArray objectAtIndex:indexPath.row];
       Dbprintertype=[DBPrintertypesArray objectAtIndex:indexPath.row];
        SearchPrinterStr=[searchPrinterArray objectAtIndex:indexPath.row];
        
    }else if (tableView==PCategorysTable){
        NSArray *PcategorypopupArray = Pcategorypopup.subviews;
        for (int i = 0; i<[PcategorypopupArray count]; i++) {
            UIView *vi =[PcategorypopupArray objectAtIndex:i];
            [vi removeFromSuperview];
            vi = nil;
        }
        [Pcategorypopup removeFromSuperview];
        
        NSString *selectedstr=[categorynamesArray objectAtIndex:indexPath.row];
        [CatBtn setTitle:selectedstr forState:UIControlStateNormal];
          selectedstr=nil;
    }else if (tableView==PdepartmentsTable){
        
        NSArray *PdeaprtmentpopupArray = Pdeaprtmentpopup.subviews;
        for (int i = 0; i<[PdeaprtmentpopupArray count]; i++) {
            UIView *vi =[PdeaprtmentpopupArray objectAtIndex:i];
            [vi removeFromSuperview];
            vi = nil;
        }
        [Pdeaprtmentpopup removeFromSuperview];
        
        NSString *selectedstr=[DepartmentNamesArray objectAtIndex:indexPath.row];
        [DeptBtn setTitle:selectedstr forState:UIControlStateNormal];
          selectedstr=nil;
    }else if (tableView==ItemsDataTable){
        
        ItemsDataTable.hidden=YES;
        
        NSString *selectedstr=[SearchDataArray objectAtIndex:indexPath.row];
        SearchField.text=selectedstr;
          selectedstr=nil;
    }else if (tableView==CashlistTable){
        
        CashlistTable.hidden=YES;
        
        paymentType=[paytypesArray objectAtIndex:indexPath.row];
          [CashDropDown setTitle:paymentType forState:UIControlStateNormal];
        
    }else if (tableView==SearchlistTable){
        
        NSArray *SearchViewpopupArray = SearchView.subviews;
        for (int i = 0; i<[SearchViewpopupArray count]; i++) {
            UIView *vi =[SearchViewpopupArray objectAtIndex:i];
            [vi removeFromSuperview];
            vi = nil;
        }
        NSArray *SearchViewArray = SearchViewpopup.subviews;
        for (int i = 0; i<[SearchViewArray count]; i++) {
            UIView *vi =[SearchViewArray objectAtIndex:i];
            [vi removeFromSuperview];
            vi = nil;
        }
        [SearchView removeFromSuperview],[SearchViewpopup removeFromSuperview];
        
        NSString *item=[ItemnameArray objectAtIndex:indexPath.row];
        [self itemclickmethod:item];
        [ProductslistTable reloadData];
        
        [self GetTotalAmountMethod];
        [ItemNumbersArray removeAllObjects],[ItemnameArray removeAllObjects], [productDesArray removeAllObjects],[priceyouchargeArray removeAllObjects],[InstockArray removeAllObjects],[VendorpartNosArray removeAllObjects];

        ItemNumbersArray=nil;
        ItemnameArray=nil;
        productDesArray=nil;
        //SnosArray=nil;
        priceyouchargeArray=nil;
        InstockArray=nil;
        VendorpartNosArray=nil;
        
    }else if (tableView==ProductslistTable){
        
        indexNO=indexPath.row;
        itemselected=YES;
       
        
    }else if ( tableView==CustomerlistTable){
        
        [self customerViewRemovemethod];
        
        CustomerNO=[CustomerNosArray objectAtIndex:indexPath.row-1];
         CustomerName=[CuFirstnamesArray objectAtIndex:indexPath.row-1];
         CusomerCompany=[ShCompanynamesArray objectAtIndex:indexPath.row-1];
         CustomerPhoneNumber=[ShPhonenumbersArray objectAtIndex:indexPath.row-1];
        
        InVoiceCustomer=CustomerNO;
        
        Customernamelbl.text=[NSString stringWithFormat:@"%@%@",@"Customer Name=",CustomerName];
        CustomerNolbl.text=[NSString stringWithFormat:@"%@%@",@"CustomerNumber=",CustomerNO];
                            
       [CustomerNosArray removeAllObjects],[CuFirstnamesArray removeAllObjects], [CuLastnamesArray removeAllObjects],[CuSnosArray removeAllObjects];
      
        CustomerNosArray=nil;
        CuFirstnamesArray=nil;
        CuLastnamesArray=nil;
        CuSnosArray=nil;
        
    
    }else if (tableView==CustomerDataTable){
        CustomerDataTable.hidden=YES;
        
        NSString *item=[CustomerDataArray objectAtIndex:indexPath.row];
        CustomerSearchField.text=item;
        item=nil;
        
    }else if (tableView==MinitsTable){
        [MinitsPopup removeFromSuperview];
        
        NSString *item=[MinitsArray objectAtIndex:indexPath.row];
        [DepTimesArray removeObjectAtIndex:SelectedTime];
        [DepTimesArray insertObject:item atIndex:SelectedTime];
        
        [ProductPrintertable reloadData];
         item=nil;
        //CustomerSearchField.text=item;
        
    }else if (tableView==PrinterNamesTable){
        NSArray *printerPopupArray = printerPopup.subviews;
        for (int i = 0; i<[printerPopupArray count]; i++) {
            UIView *vi =[printerPopupArray objectAtIndex:i];
            [vi removeFromSuperview];
            vi = nil;
        }
        [printerPopup removeFromSuperview];
        
        NSString *item=[PrinterNamesArray objectAtIndex:indexPath.row];
        
        [DepPrinterDataArray removeObjectAtIndex:SelectedPrinter];
        [DepPrinterDataArray insertObject:item atIndex:SelectedPrinter];
          [ProductPrintertable reloadData];
        //CustomerSearchField.text=item;
         item=nil;
    }else if (tableView==FecthOnHoldlistTable){
        //[self ProductPrinterMethod];
        
        NSString *selectedID=[InVoiceIdsArray objectAtIndex:indexPath.row];
        HoldID=[HoldIdsArray objectAtIndex:indexPath.row];
        invoiceID=[InVoiceIdsArray objectAtIndex:indexPath.row];
        
    
        
        NSString *querySQL = [NSString stringWithFormat: @"SELECT item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer FROM invoice_items_table WHERE invoice_id='%@'",selectedID];
        
        NSMutableArray *invitemsArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:invitemsArray];
        @autoreleasepool {
            for (NSDictionary *myDict in invitemsArray)
            {
                NSString *itemstr=[myDict objectForKey:@"invoice_id"];
                if ([itemstr isEqualToString:selectedID])
                {
                    NSString *itemno=[myDict objectForKey:@"item_id"];
                    NSString *Qty=[myDict objectForKey:@"item_quantity"];
                    NSString *price=[myDict objectForKey:@"price_you_charge"];
                    
                    
                    
                    if ([ItemNosArray count]>0)
                    {
                        NSUInteger objIdx = [ItemNosArray containsObject:itemno];
                        // // //NSLog(@"%lu",(unsigned long)objIdx);
                        if(objIdx == 0)
                        {
                            [ItemNosArray addObject:[myDict objectForKey:@"item_id"]];
                            [ItemNamesArray addObject:[myDict objectForKey:@"item_name"]];
                            [QntysArray addObject:[myDict objectForKey:@"item_quantity"]];
                            [pricesArray addObject:[myDict objectForKey:@"price_you_charge"]];
                            [TaxesArray addObject:[myDict objectForKey:@"total_tax"]];
                            [AvegCostsArray addObject:[myDict objectForKey:@"avg_cost"]];
                            [DiscountsArray addObject:[myDict objectForKey:@"discount"]];
                            
                            [ItemVendorArray addObject:[myDict objectForKey:@"in_vendor"]];
                            [ItemDeptsArray addObject:[myDict objectForKey:@"in_department"]];
                            [ItemDesArray addObject:[myDict objectForKey:@"item_desscription"]];
                            
                            
                        }
                        else
                        {
                            NSInteger qindex=[ItemNosArray indexOfObject:itemno];
                            NSString *anotherqty=[QntysArray objectAtIndex:qindex];
                            NSString *anotherprice=[pricesArray objectAtIndex:qindex];
                            
                            
                            
                            quantity=[anotherqty intValue]+[Qty intValue];
                            Pricevalue=[anotherprice doubleValue]+[price doubleValue];
                            
                            
                            [QntysArray removeObjectAtIndex:qindex];
                            [pricesArray removeObjectAtIndex:qindex];
                            [QntysArray insertObject:[NSString stringWithFormat:@"%d",quantity] atIndex:qindex];
                            [pricesArray insertObject:[NSString stringWithFormat:@"%0.02f",Pricevalue] atIndex:qindex];
                            
                            
                        }
                    }
                    else
                    {
                        
                        [ItemNosArray addObject:[myDict objectForKey:@"item_id"]];
                        [ItemNamesArray addObject:[myDict objectForKey:@"item_name"]];
                        [QntysArray addObject:[myDict objectForKey:@"item_quantity"]];
                        [pricesArray addObject:[myDict objectForKey:@"price_you_charge"]];
                        [TaxesArray addObject:[myDict objectForKey:@"total_tax"]];
                        [AvegCostsArray addObject:[myDict objectForKey:@"avg_cost"]];
                        [DiscountsArray addObject:[myDict objectForKey:@"discount"]];
                        
                        [ItemVendorArray addObject:[myDict objectForKey:@"in_vendor"]];
                        [ItemDeptsArray addObject:[myDict objectForKey:@"in_department"]];
                        [ItemDesArray addObject:[myDict objectForKey:@"item_desscription"]];
                        
                    }
            
                }
                [SnosArray addObject:[NSString stringWithFormat:@"%d",[ItemNamesArray count]]];
                
            }
        }
        selectedID=nil;
        [ProductslistTable reloadData];
        
        [self GetTotalAmountMethod];
        NSArray *FetchOnHoldBackViewArray = FetchOnHoldBackView.subviews;
        for (int i = 0; i<[FetchOnHoldBackViewArray count]; i++) {
            UIView *vi =[FetchOnHoldBackViewArray objectAtIndex:i];
            [vi removeFromSuperview];
            vi = nil;
        }
        NSArray *FetchOnHoldViewArray = FetchOnHoldView.subviews;
        for (int i = 0; i<[FetchOnHoldViewArray count]; i++) {
            UIView *vi =[FetchOnHoldViewArray objectAtIndex:i];
            [vi removeFromSuperview];
            vi = nil;
        }
        [FetchOnHoldView removeFromSuperview],[FetchOnHoldBackView removeFromSuperview];
        
         [retraiveOnHoldBtn setTitle:@"Save on Hold" forState:UIControlStateNormal];
    }else if (tableView==RecallListTable){
        NSString *selectedID=[InVoiceIdsArray objectAtIndex:indexPath.row];
      //  HoldID=[HoldIdsArray objectAtIndex:indexPath.row];
       // invoiceID=[InVoiceIdsArray objectAtIndex:indexPath.row];
        
        RecallInvoiceID=selectedID;
        
        
        NSString *querySQL = [NSString stringWithFormat: @"SELECT item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer FROM invoice_items_table WHERE invoice_id='%@'",selectedID];
        NSMutableArray *invitemsArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:invitemsArray];
       
        @autoreleasepool {
            
        for (NSDictionary *myDict in invitemsArray)
        {
            NSString *itemstr=[myDict objectForKey:@"invoice_id"];
            if ([itemstr isEqualToString:selectedID])
            {
                NSString *itemno=[myDict objectForKey:@"item_id"];
                NSString *Qty=[myDict objectForKey:@"item_quantity"];
                NSString *price=[myDict objectForKey:@"price_you_charge"];
             if ([ItemNosArray count]>0)
                {
                    NSUInteger objIdx = [ItemNosArray containsObject:itemno];
                   // // //NSLog(@"%lu",(unsigned long)objIdx);
                    if(objIdx == 0)
                    {
                        [ItemNosArray addObject:[myDict objectForKey:@"item_id"]];
                        [ItemNamesArray addObject:[myDict objectForKey:@"item_name"]];
                        [QntysArray addObject:[myDict objectForKey:@"item_quantity"]];
                        [pricesArray addObject:[myDict objectForKey:@"price_you_charge"]];
                        [TaxesArray addObject:[myDict objectForKey:@"total_tax"]];
                        [AvegCostsArray addObject:[myDict objectForKey:@"avg_cost"]];
                        [DiscountsArray addObject:[myDict objectForKey:@"discount"]];
                        
                        [ItemVendorArray addObject:[myDict objectForKey:@"in_vendor"]];
                        [ItemDeptsArray addObject:[myDict objectForKey:@"in_department"]];
                        [ItemDesArray addObject:[myDict objectForKey:@"item_desscription"]];
                        
                        
                    }
                    else
                    {
                        NSInteger qindex=[ItemNosArray indexOfObject:itemno];
                        NSString *anotherqty=[QntysArray objectAtIndex:qindex];
                        NSString *anotherprice=[pricesArray objectAtIndex:qindex];
                        
                        
                        
                        quantity=[anotherqty intValue]+[Qty intValue];
                        Pricevalue=[anotherprice doubleValue]+[price doubleValue];
                        
                        
                        [QntysArray removeObjectAtIndex:qindex];
                        [pricesArray removeObjectAtIndex:qindex];
                        [QntysArray insertObject:[NSString stringWithFormat:@"%d",quantity] atIndex:qindex];
                        [pricesArray insertObject:[NSString stringWithFormat:@"%0.02f",Pricevalue] atIndex:qindex];
                        
                        
                    }
                }
                else
                {
                    
                    [ItemNosArray addObject:[myDict objectForKey:@"item_id"]];
                    [ItemNamesArray addObject:[myDict objectForKey:@"item_name"]];
                    [QntysArray addObject:[myDict objectForKey:@"item_quantity"]];
                    [pricesArray addObject:[myDict objectForKey:@"price_you_charge"]];
                    [TaxesArray addObject:[myDict objectForKey:@"total_tax"]];
                    [AvegCostsArray addObject:[myDict objectForKey:@"avg_cost"]];
                    [DiscountsArray addObject:[myDict objectForKey:@"discount"]];
                    
                    [ItemVendorArray addObject:[myDict objectForKey:@"in_vendor"]];
                    [ItemDeptsArray addObject:[myDict objectForKey:@"in_department"]];
                    [ItemDesArray addObject:[myDict objectForKey:@"item_desscription"]];
                    
                }
                
                
                
            }
            [SnosArray addObject:[NSString stringWithFormat:@"%d",[ItemNamesArray count]]];
            
        }
     }
        
        [PayBtn setTitle:@"Clear Display" forState:UIControlStateNormal];
        
        [ProductslistTable reloadData];
        
        [self GetTotalAmountMethod];
        RecallinvoiceValue=YES;
        
        [self releaseAllviewsmethod];
        [InVoiceIdsArray removeAllObjects],[TotalAmountsArray removeAllObjects],[paymentTypesArray removeAllObjects],[HoldIdsArray removeAllObjects],[RsonsArray removeAllObjects];
       InVoiceIdsArray=nil;
        TotalAmountsArray=nil;
        paymentTypesArray=nil;
        HoldIdsArray=nil;
        TimesArray=nil;
        RsonsArray=nil;
        selectedID=nil;
    }
    
}
-(void)departmentselected:(NSString *)department
{
    NSString *querySQL = [NSString stringWithFormat:@"SELECT inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor,check_value FROM inventorytable WHERE inventary_department='%@'",department];
    NSMutableArray *productDataArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:productDataArray];
   
    @autoreleasepool {
        for (NSDictionary *myDict in productDataArray)
        {
            NSString *valuesstr=[myDict objectForKey:@"inventary_department"];
            if ([valuesstr isEqualToString:department]){
                NSString *check=[myDict objectForKey:@"check_value"];
                if ([check isEqualToString:@"true"]){
                    [ItemsArray addObject:[myDict objectForKey:@"inventary_item_name"]];
                }
            }
            valuesstr=nil;
        }
    }
    NSArray *mainArray = itemsView.subviews;
    for (int i = 0; i<[mainArray count]; i++) {
        UIView *vi =[mainArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [ItemBtn removeFromSuperview];
    [itemsView removeFromSuperview];
    itemsView=nil,ItemBtn=nil;
    [self ItemsAddmethod];
    ////NSLog(@"items array %@",ItemsArray);
}
-(void)customerViewRemovemethod
{
    NSArray *CustomerViewpopupArray = CustomerViewpopup.subviews;
    for (int i = 0; i<[CustomerViewpopupArray count]; i++) {
        UIView *vi =[CustomerViewpopupArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *CustomerViewArray = CustomerView.subviews;
    for (int i = 0; i<[CustomerViewArray count]; i++) {
        UIView *vi =[CustomerViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [CustomerView removeFromSuperview],[CustomerViewpopup removeFromSuperview];
}
- (IBAction)fetch_editButtonClicked:(id)sender
{
    UIButton *but =sender;
    // //NSLog(@"EditButton %d",but.tag);
    
    NSInteger selected=but.tag;
    NSString *holdid=[HoldIdsArray objectAtIndex:selected];
    if (!ProductNamesArray)
    ProductNamesArray=[[NSMutableArray alloc]init];
    //ProductNamesArray=ItemNamesArray;
     if (!DepPrinterDataArray)
    DepPrinterDataArray=[[NSMutableArray alloc]init];
     if (!DepTimesArray)
    DepTimesArray=[[NSMutableArray alloc]init];
      if (!QtyitemsArry)
    QtyitemsArry=[[NSMutableArray alloc]init];
    
   NSString *querySQL = [NSString stringWithFormat: @"SELECT department_printer,department_print_time,item_name,message,hold_id FROM printer_commands "];
    NSMutableArray *printerDataArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:printerDataArray];
    
 
    for (NSDictionary *myDict in printerDataArray)
    {
        NSString *Pholdid=[myDict objectForKey:@"hold_id"];
        if ([Pholdid isEqualToString:holdid])
        {
            NSString *time=[myDict objectForKey:@"department_print_time"];
            
            [DepPrinterDataArray addObject:[myDict objectForKey:@"department_printer"]];
            [QtyitemsArry addObject:[myDict objectForKey:@"message"]];
            
            
            NSDate *today = [NSDate date];
            NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
            [formatter setDateFormat:@"HH:mm"];
            NSString *Pdate=[formatter stringFromDate:today];
            NSArray *hoursMins2 = [Pdate componentsSeparatedByString:@":"];
            NSInteger timeInMins2 = [hoursMins2[0] intValue] * 60 + [hoursMins2[1] intValue];
            
            NSArray *hoursMins = [time componentsSeparatedByString:@":"];
            NSInteger timeInMins = [hoursMins[0] intValue] * 60 + [hoursMins[1] intValue];
            // // //NSLog(@"%ld",(long)timeInMins);
            NSDateFormatter *df = [[NSDateFormatter alloc] init];
            [df setDateFormat:@"HH:mm"];
            //NSDate *date = [df dateFromString:time];
            // //NSLog(@"%@",date);
            NSInteger Timediff=timeInMins-timeInMins2;
            // // //NSLog(@"%ld",(long)Timediff);
            
            [DepTimesArray addObject:[NSString stringWithFormat:@"%ld",(long)Timediff]];
            [ProductNamesArray addObject:[myDict objectForKey:@"item_name"]];
            
            
            
        }
        
    }
    if (!ProductPrinterPopUp)
    ProductPrinterPopUp=[[UIView alloc]init];
    if (isLandScope) {
        ProductPrinterPopUp.frame=CGRectMake(0, 0, 1024, 768);
    }
    
    else{
        
        ProductPrinterPopUp.frame=CGRectMake(0, 0, 768, 1024);
    }
    [ProductPrinterPopUp setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    
    [self.view addSubview:ProductPrinterPopUp];
     if (!ProductPrinterView)
    ProductPrinterView=[[UIScrollView alloc]init];
    ProductPrinterView.frame=CGRectMake(20, 100, ProductPrinterPopUp.frame.size.width-40, ProductPrinterPopUp.frame.size.height-200);
    [ProductPrinterView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    ProductPrinterView.contentSize=CGSizeMake(ProductPrinterPopUp.frame.size.width-40, ProductPrinterPopUp.frame.size.height+300);
    [ProductPrinterView.layer setBorderWidth:2.0];
    [ProductPrinterView.layer setBorderColor:[[UIColor whiteColor] CGColor]];
    //AddvendorsView.layer.cornerRadius=8;
    [ProductPrinterPopUp addSubview:ProductPrinterView];
    
    CGFloat changeProductfieldwidth=(ProductPrinterView.frame.size.width)/2;
    
     if (!PrintTextlbl)
    PrintTextlbl=[[UILabel alloc] init];
    PrintTextlbl.frame=CGRectMake(changeProductfieldwidth-180, 10,changeProductfieldwidth, 30);
    [PrintTextlbl setFont:[UIFont systemFontOfSize:25.0f]];
    [PrintTextlbl setBackgroundColor:[UIColor clearColor]];
    [PrintTextlbl setTextColor:[UIColor whiteColor]];
    [PrintTextlbl setText:@"Send Printout to Department"];
    PrintTextlbl.lineBreakMode = NSLineBreakByWordWrapping;
    PrintTextlbl.numberOfLines = 2;
    [PrintTextlbl setTextAlignment:NSTextAlignmentLeft];
    [ProductPrinterView addSubview:PrintTextlbl];
     if (!ProductPrintertable)
    ProductPrintertable = [[UITableView alloc] initWithFrame:CGRectMake(10,60, ProductPrinterView.frame.size.width-20,ProductPrinterView.frame.size.height-300)];
    
    ProductPrintertable.backgroundColor=[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f];
    ProductPrintertable.delegate = self;
    ProductPrintertable.dataSource = self;
    ProductPrintertable.scrollEnabled = YES;
    [ProductPrinterView addSubview:ProductPrintertable];
     if (!SavePrintBtn)
    SavePrintBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    SavePrintBtn.frame=CGRectMake(changeProductfieldwidth-80,ProductPrinterView.frame.size.height-100 , 80, 30);
    [SavePrintBtn addTarget:self action:@selector(EditYESProductPrinterData) forControlEvents:UIControlEventTouchUpInside];
    
    [SavePrintBtn setTitle:@"YES" forState:UIControlStateNormal];
    [SavePrintBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [SavePrintBtn setBackgroundImage:[UIImage imageNamed:@"additionaloptionspressed.png"] forState:UIControlStateNormal];
    [ProductPrinterView addSubview:SavePrintBtn];
     if (!CancelPrintBtn)
    CancelPrintBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
   CancelPrintBtn.frame=CGRectMake(changeProductfieldwidth+40, ProductPrinterView.frame.size.height-100 , 80, 30);
    [CancelPrintBtn addTarget:self action:@selector(NoProductPrinter2) forControlEvents:UIControlEventTouchUpInside];
    [CancelPrintBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [CancelPrintBtn setBackgroundImage:[UIImage imageNamed:@"additionaloptionspressed.png"] forState:UIControlStateNormal];
    [CancelPrintBtn setTitle:@"NO" forState:UIControlStateNormal];
    [ProductPrinterView addSubview:CancelPrintBtn];
}
- (IBAction)fetch_deleteButtonClicked:(id)sender
{
    UIButton *but =sender;
    // //NSLog(@"EditButton %d",but.tag);
    
    selectededInvoice=but.tag;
    DeleteInvoiceAlert=[[UIAlertView alloc]initWithTitle:@"Delete All" message:@"Are you sure want to delete" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil];
    [DeleteInvoiceAlert show];
}
- (IBAction)productData_deleteButtonClicked:(id)sender
{
    UIButton *but =sender;
    // //NSLog(@"EditButton %d",but.tag);
    if ([[generalDataObject  userType] isEqualToString:@"employee"])
    {
        if ([[generalDataObject  delete_items_permission] isEqualToString:@"yes"])
        {
            NSInteger selected=but.tag;
            [ItemNamesArray removeObjectAtIndex:selected];
            [ItemNosArray removeObjectAtIndex:selected];
            [QntysArray removeObjectAtIndex:selected];
            [pricesArray removeObjectAtIndex:selected];
            [SnosArray removeObjectAtIndex:selected];
            [TaxesArray removeObjectAtIndex:selected];
            
            [AvegCostsArray removeObjectAtIndex:selected];
            [DiscountsArray removeObjectAtIndex:selected];
            
            [ItemVendorArray removeObjectAtIndex:selected];
            [ItemDeptsArray removeObjectAtIndex:selected];
            [ItemDesArray removeObjectAtIndex:selected];
            [ProductslistTable reloadData];
            [self GetTotalAmountMethod];
            itemcount=0;
            if ([ItemNamesArray count]==0)
            {
                [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
                [PayBtn setTitle:@"Pay" forState:UIControlStateNormal];
                
                RecallinvoiceValue=NO;
                
                [SearchBtn addTarget:self action:@selector(SearchBtnClicked) forControlEvents:UIControlEventTouchUpInside];
                [DeleteBtn addTarget:self action:@selector(DeleteAllDataClicked) forControlEvents:UIControlEventTouchUpInside];
                [DiscountBtn addTarget:self action:@selector(ChangeDiscountClicked) forControlEvents:UIControlEventTouchUpInside];
                [PriceChangeBtn addTarget:self action:@selector(PriceChangeClciked) forControlEvents:UIControlEventTouchUpInside];
                
                [CreditBtn addTarget:self action:@selector(CreditBtnClicked) forControlEvents:UIControlEventTouchUpInside];
                
                [CheckBtn addTarget:self action:@selector(CheckBtnClicked) forControlEvents:UIControlEventTouchUpInside];
                [CashBtn addTarget:self action:@selector(CashBtnClicked) forControlEvents:UIControlEventTouchUpInside];
                [VoidInVoiceBtn addTarget:self action:@selector(VoidinVoiceClicked) forControlEvents:UIControlEventTouchUpInside];
                [ItemBtn addTarget:self action:@selector(ItemClicked:) forControlEvents:UIControlEventTouchUpInside];
                [FindBtn addTarget:self action:@selector(FindCustomerClicked) forControlEvents:UIControlEventTouchUpInside];
                [AddBtn addTarget:self action:@selector(AddCustomerClicked) forControlEvents:UIControlEventTouchUpInside];
                
                [retraiveOnHoldBtn addTarget:self action:@selector(FetchOnHoldClicked) forControlEvents:UIControlEventTouchUpInside];
            }
            
        }
        else
        {
            UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
            
            [authalert show];
            authalert=nil;
        }
    }else{
        NSInteger selected=but.tag;
        [ItemNamesArray removeObjectAtIndex:selected];
        [ItemNosArray removeObjectAtIndex:selected];
        [QntysArray removeObjectAtIndex:selected];
        [pricesArray removeObjectAtIndex:selected];
        [SnosArray removeObjectAtIndex:selected];
        [TaxesArray removeObjectAtIndex:selected];
        
        [AvegCostsArray removeObjectAtIndex:selected];
        [DiscountsArray removeObjectAtIndex:selected];
        
        [ItemVendorArray removeObjectAtIndex:selected];
        [ItemDeptsArray removeObjectAtIndex:selected];
        [ItemDesArray removeObjectAtIndex:selected];
        
        [ProductslistTable reloadData];
        
        [self GetTotalAmountMethod];
        itemcount=0;
        if ([ItemNamesArray count]==0)
        {
            [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
            [PayBtn setTitle:@"Pay" forState:UIControlStateNormal];
            
            RecallinvoiceValue=NO;
            
            [SearchBtn addTarget:self action:@selector(SearchBtnClicked) forControlEvents:UIControlEventTouchUpInside];
            [DeleteBtn addTarget:self action:@selector(DeleteAllDataClicked) forControlEvents:UIControlEventTouchUpInside];
            [DiscountBtn addTarget:self action:@selector(ChangeDiscountClicked) forControlEvents:UIControlEventTouchUpInside];
            [PriceChangeBtn addTarget:self action:@selector(PriceChangeClciked) forControlEvents:UIControlEventTouchUpInside];
            
            [CreditBtn addTarget:self action:@selector(CreditBtnClicked) forControlEvents:UIControlEventTouchUpInside];
            
            [CheckBtn addTarget:self action:@selector(CheckBtnClicked) forControlEvents:UIControlEventTouchUpInside];
            [CashBtn addTarget:self action:@selector(CashBtnClicked) forControlEvents:UIControlEventTouchUpInside];
            [VoidInVoiceBtn addTarget:self action:@selector(VoidinVoiceClicked) forControlEvents:UIControlEventTouchUpInside];
            [ItemBtn addTarget:self action:@selector(ItemClicked:) forControlEvents:UIControlEventTouchUpInside];
            [FindBtn addTarget:self action:@selector(FindCustomerClicked) forControlEvents:UIControlEventTouchUpInside];
            [AddBtn addTarget:self action:@selector(AddCustomerClicked) forControlEvents:UIControlEventTouchUpInside];
            [retraiveOnHoldBtn addTarget:self action:@selector(FetchOnHoldClicked) forControlEvents:UIControlEventTouchUpInside];
        }
        
    }
}

-(void)EditYESProductPrinterData
{
    NSString *updateSQL =@"DELETE FROM printer_commands WHERE hold_id=?";
    
    NSMutableArray *deleteArray=[[NSMutableArray alloc]initWithObjects:HoldID, nil];
    [[DataBaseManager dataBaseManager]executeRecordsWithQuery:updateSQL withArguments:deleteArray];
    updateSQL=nil;
    
    NSArray *ProductPrinterPopUpArray = ProductPrinterPopUp.subviews;
    for (int i = 0; i<[ProductPrinterPopUpArray count]; i++) {
        UIView *vi =[ProductPrinterPopUpArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *ProductPrinterViewArray = ProductPrinterView.subviews;
    for (int i = 0; i<[ProductPrinterViewArray count]; i++) {
        UIView *vi =[ProductPrinterViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [ProductPrinterView removeFromSuperview],[ProductPrinterPopUp removeFromSuperview];
    [self YESProductPrinterData];
    
}
-(void)NoProductPrinter2
{
    NSArray *ProductPrinterPopUpArray = ProductPrinterPopUp.subviews;
    for (int i = 0; i<[ProductPrinterPopUpArray count]; i++) {
        UIView *vi =[ProductPrinterPopUpArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *ProductPrinterViewArray = ProductPrinterView.subviews;
    for (int i = 0; i<[ProductPrinterViewArray count]; i++) {
        UIView *vi =[ProductPrinterViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [ProductPrinterView removeFromSuperview],[ProductPrinterPopUp removeFromSuperview];
}

-(void)PrinterName:(UIButton *)sender
{
    SelectedPrinter=sender.tag;
    
    
    
    NSString *querySQL5 = [NSString stringWithFormat: @"SELECT printname FROM printer"];
    NSMutableArray *printersArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL5 resultsArray:printersArray];
    
    
    PrinterNamesArray=[[NSMutableArray alloc]init];
    
    [PrinterNamesArray addObject:@"None"];
    
    for (NSDictionary *myDict in printersArray)
    {
        
        NSString *catname=[myDict objectForKey:@"printname"];
        [PrinterNamesArray addObject:catname];
        
    }
    if (!printerPopup)
    printerPopup=[[UIView alloc]init];
    if (isLandScope) {
        printerPopup.frame=CGRectMake(0, 0, 1024, 768);
    }
    
    else{
        
        printerPopup.frame=CGRectMake(0, 0, 768, 1024);
    }
    [printerPopup setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:printerPopup];
     if (!PrinterNamesTable)
    PrinterNamesTable=[[UITableView alloc]init];
    //[editProductTable  setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    [PrinterNamesTable setBackgroundColor:[UIColor whiteColor]];
    PrinterNamesTable.frame=CGRectMake(100,200 ,printerPopup.frame.size.width-200, printerPopup.frame.size.height-400);
    
    //editProductTable.contentSize = CGSizeMake(ProductView.frame.size.width+1000, ProductView.frame.size.height+1000);
    PrinterNamesTable.delegate=self;
    PrinterNamesTable.dataSource=self;
    [printerPopup addSubview:PrinterNamesTable];
    
    
    
}
-(void)TimeBtn:(UIButton *)sender
{
    SelectedTime=sender.tag;
    if (!MinitsArray)
     MinitsArray=[[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56",@"57",@"58",@"59",nil];
    if (!MinitsPopup)
    MinitsPopup=[[UIView alloc]init];
    if (isLandScope) {
        MinitsPopup.frame=CGRectMake(0, 0, 1024, 768);
    }
    
    else{
        
        MinitsPopup.frame=CGRectMake(0, 0, 768, 1024);
    }
    [MinitsPopup setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:MinitsPopup];
    if (!MinitsTable)
    MinitsTable=[[UITableView alloc]init];
    //[editProductTable  setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    [MinitsTable setBackgroundColor:[UIColor whiteColor]];
    MinitsTable.frame=CGRectMake(100,200 ,MinitsPopup.frame.size.width-200, MinitsPopup.frame.size.height-400);
    
    //MinitsTable = CGSizeMake(ProductView.frame.size.width+1000, ProductView.frame.size.height+1000);
    MinitsTable.delegate=self;
    MinitsTable.dataSource=self;
    
    [MinitsPopup addSubview:MinitsTable];
    
    
    
}
-(void)textFiledDidChange:(UITextField *)sender
{
    NSInteger selectedF=sender.tag;
    [QtyitemsArry removeObjectAtIndex:selectedF];
    [QtyitemsArry insertObject:sender.text atIndex:selectedF];
    [ProductPrintertable reloadData];
    
    
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
    if (RecallinvoiceValue==YES)
    {
        
        if(textField == ProductscanField)
        {
            [textField resignFirstResponder];
            // Show you custom picker here....
            return NO;
        }
        
        if(textField == QantyField)
        {
            [textField resignFirstResponder];
            // Show you custom picker here....
            return NO;
        }
    }
    
    return YES;
}

-(void)PrinterViewMethod
{
    
       // // //NSLog(@"%d",indexNO);
    
    
        PrinterpopupView=[[UIView alloc]init];
        if (isLandScope) {
            PrinterpopupView.frame=CGRectMake(0, 0, 1024, 768);
        }
        
        else{
            
            PrinterpopupView.frame=CGRectMake(0, 0, 768, 1024);
        }
        [PrinterpopupView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
        [self.view addSubview:PrinterpopupView];
        
        PrinterView=[[UIScrollView alloc]init];
        if (isLandScope)
        {
            PrinterView.frame=CGRectMake(200, 200, PrinterpopupView.frame.size.width-400, PrinterpopupView.frame.size.height-400);
        }
        else
        {
            PrinterView.frame=CGRectMake(150, 300, PrinterpopupView.frame.size.width-300, PrinterpopupView.frame.size.height-700);
        }
        
        [PrinterView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
        
        [PrinterView.layer setBorderWidth:2.0];
        [PrinterView.layer setBorderColor:[[UIColor whiteColor] CGColor]];
        //AddvendorsView.layer.cornerRadius=8;
        [PrinterpopupView addSubview:PrinterView];
        
        
        CGFloat instwidth=(PrinterView.frame.size.width)/2;
        CGFloat inst=instwidth/2;
    
    
    textlbl=[[UILabel alloc] init];
    textlbl.frame=CGRectMake(inst, 5,instwidth, 40);
    
    [textlbl setFont:[UIFont systemFontOfSize:22.0f]];
    [textlbl setBackgroundColor:[UIColor clearColor]];
    [textlbl setTextColor:[UIColor whiteColor]];
    [textlbl setText:@"Do you want Receipt?"];
    textlbl.lineBreakMode = NSLineBreakByWordWrapping;
    textlbl.numberOfLines = 2;
    [textlbl setTextAlignment:NSTextAlignmentLeft];
    [PrinterView addSubview:textlbl];
    
    
        selectprinterlbl=[[UILabel alloc] init];
        selectprinterlbl.frame=CGRectMake(inst-60, 45,instwidth, 40);
        
        [selectprinterlbl setFont:[UIFont systemFontOfSize:25.0f]];
        [selectprinterlbl setBackgroundColor:[UIColor clearColor]];
        [selectprinterlbl setTextColor:[UIColor whiteColor]];
        [selectprinterlbl setText:@"Select Printer"];
        selectprinterlbl.lineBreakMode = NSLineBreakByWordWrapping;
        selectprinterlbl.numberOfLines = 2;
        [selectprinterlbl setTextAlignment:NSTextAlignmentLeft];
        [PrinterView addSubview:selectprinterlbl];
    
    
    paytypesArray=[[NSArray alloc]initWithObjects:@"Cash",@"Cheque",@"Card", nil];
    SelectPrintBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    SelectPrintBtn.frame=CGRectMake(inst-20, 95,instwidth+50, 40);
    [SelectPrintBtn addTarget:self action:@selector(SelectPrinterClicked) forControlEvents:UIControlEventTouchUpInside];
    [SelectPrintBtn setTitle:[paytypesArray objectAtIndex:0] forState:UIControlStateNormal];
    [SelectPrintBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [SelectPrintBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    [PrinterView addSubview:SelectPrintBtn];
    
    
    
    PrinterDataTable = [[UITableView alloc] initWithFrame:CGRectMake(inst-20, 135,instwidth+50, 100) style:UITableViewStylePlain];
    PrinterDataTable.backgroundColor=[UIColor whiteColor];
    PrinterDataTable.delegate = self;
    PrinterDataTable.dataSource = self;
    PrinterDataTable.scrollEnabled = YES;
    PrinterDataTable.hidden=YES;
    [PrinterDataTable.layer setBorderWidth: 1.0];
    [PrinterDataTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [PrinterView addSubview:PrinterDataTable];
    
        YesPrintBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        YesPrintBtn.frame=CGRectMake(instwidth-90, 280, 80, 30);
       // [YesPrintBtn addTarget:self action:@selector(GetPrint) forControlEvents:UIControlEventTouchUpInside];
        
        [YesPrintBtn setTitle:@"YES" forState:UIControlStateNormal];
        [YesPrintBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [YesPrintBtn setBackgroundImage:[UIImage imageNamed:@"okay-button.png"] forState:UIControlStateNormal];
        [PrinterView addSubview:YesPrintBtn];
        
        NoPrintBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        NoPrintBtn.frame=CGRectMake(instwidth+40, 280, 80, 30);
        [NoPrintBtn addTarget:self action:@selector(CancelPrint) forControlEvents:UIControlEventTouchUpInside];
        [NoPrintBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [NoPrintBtn setBackgroundImage:[UIImage imageNamed:@"okay-button.png"] forState:UIControlStateNormal];
        [NoPrintBtn setTitle:@"NO" forState:UIControlStateNormal];
        [PrinterView addSubview:NoPrintBtn];
        

}

+ (void)CheckStatusWithPortname:(NSString *)portName portSettings:(NSString *)portSettings
{
    SMPort *starPort = nil;
    
    starPort = [SMPort getPort:portName :portSettings :10000];
    if (starPort == nil)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Fail to Open Port"
                                                        message:@""
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
        
        return;
    }
}
/*- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 100) //Search Printer
    {
        if (buttonIndex == 0) //Cancel
            return;
        
        NSArray *array ;
        switch (buttonIndex)
        {
            case 1: //LAN
                array = [SMPort searchPrinter:@"TCP:"];
                break;
            case 2: //Bluetooth
                array = [SMPort searchPrinter:@"BT:"];
                break;
            case 3: //All
                array = [SMPort searchPrinter];
                break;
        }
    }
}*/
-(void)GetPrint:(UIWebView **)webview
{
    
    //UIImageView *myimageView=[[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 600, 600)];
    //[myimageView setImage:[generalDataObject   imageFromWebView:webView1]];
    // [self.view addSubview: myimageView];
    [*webview removeFromSuperview];
    
    
    //[PrinterpopupView removeFromSuperview];
    
    if ([Dbprintertype isEqualToString:@"EPSON"]){
        EposPrint *printer_ = [[EposPrint alloc] init];
        
        int result = [printer_ openPrinter:0 DeviceName:Ipadd Enabled:TRUE Interval:1000];
        if(result != EPOS_OC_SUCCESS)
        {
            [ShowMess showExceptionEpos:result method:@"openPrinter"];
            //[printer release];
            return;
        }
        
        
        //create builder
        EposBuilder *builder = [[EposBuilder alloc] initWithPrinterModel:PayPrinterName Lang:EPOS_OC_MODEL_ANK];
        if(builder == nil)
        {
            return ;
        }
        
        UIImage *printImage=[self imageFromWebView:*webview];
        CGFloat width=printImage.size.width;
        CGFloat height =printImage.size.width;
        
        //result1 = [builder addText:stringToPrint];
        result1 = [builder addImage:printImage X: 0 Y: 0 Width: width Height: height Color: EPOS_OC_PARAM_DEFAULT];
        
        result1 = [builder addCut: EPOS_OC_CUT_FEED];
        if(result1 != EPOS_OC_SUCCESS){
            [ShowMess showExceptionEpos:result1 method:@"addImage"];
            return ;
        }
        
        result1 = [builder addFeedUnit:[[NSString stringWithFormat:@"%@",unit] intValue]];
        if(result1 != EPOS_OC_SUCCESS){
            [ShowMess showExceptionEpos:result1 method:@"addFeedUnit"];
            return ;
            
        }
        
        //send builder data
        unsigned long status = 0;
        unsigned long battery = 0;
        result1 = [printer_ sendData:builder Timeout:10000 Status:&status Battery:&battery];
        [ShowMess showStatus:result1 status:status battery:battery];
        
        
        //remove builder
        [builder clearCommandBuffer];
       
        printImage=Nil;
        
    }else if ([Dbprintertype isEqualToString:@"STAR"]){
        
        if (blocking == YES)
        {
            return;
        }
        blocking = YES;
        
        
        // CGFloat imagewidth = [self imageFromWebView:webView1].size.width;
        
        //        [PrinterFunctions PrintTextWithPortname:@"TCP:192.168.1.12" portSettings:@"TCP:192.168.1.12" slashedZero:slashedZero underline:underLine invertColor:invertColor emphasized:emphasized upperline:upperline upsideDown:upsideDown heightExpansion:height widthExpansion:width leftMargin:leftMargin alignment:alignment textData:textData textDataSize:[textNSData length]];
        
        NSString *ipaddress=[NSString stringWithFormat:@"%@:%@",SearchPrinterStr,Ipadd];
        // //NSLog(@"ipaddress  %@",ipaddress);
        
        UIImage *printImage=[self imageFromWebView:*webview];
        CGFloat imagewidth=printImage.size.width;
        
        [PrinterFunctions PrintImageWithPortname:ipaddress portSettings:ipaddress imageToPrint:printImage maxWidth:imagewidth compressionEnable:YES withDrawerKick:YES];
        printImage=Nil;
        // free(textData);
        blocking = NO;
        
    }
    [*webview loadRequest:nil];
    *webview=nil;
}

-(void)SelectPrinterClicked
{
    if (PrinterDataTable.hidden==1){
        
        PrinterDataTable.hidden=NO;
   
    }else if (PrinterDataTable.hidden==0){
        
        [PrinterDataTable setHidden:YES];
        
    }
}
-(void)UpdateInVoiceDataMethod
{
     double totlaprofit=SubtotalValue-TotalAvegCost;
    
    //double totlaprofit=SubtotalValue-TotalAvegCost;
    if ([ItemsArray count]>0)
    {
        @autoreleasepool {
            for (int i=0; i<[ItemNosArray count]; i++)
            {
                NSString *insertSQL;
                
                NSString *ID=[ItemNosArray objectAtIndex:i];
                NSString *Discount=[DiscountsArray objectAtIndex:i];
                NSString *itemname=[ItemNamesArray objectAtIndex:i];
                NSString *des=[ItemDesArray objectAtIndex:i];
                NSString *price=[pricesArray objectAtIndex:i];
                NSString *avegcost=[AvegCostsArray objectAtIndex:i];
                NSString *Qty=[QntysArray objectAtIndex:i];
                NSString *Dept=[ItemDeptsArray objectAtIndex:i];
                NSString *Vendor=[ItemVendorArray objectAtIndex:i];
                NSString *Ttax=[TaxesArray objectAtIndex:i];
                
                insertSQL =@"UPDATE  invoice_items_table SET item_id=?, discount=?,total_tax=?,item_name=?,item_desscription=?,price_you_charge=?,avg_cost=?,item_quantity=?,in_department=?,in_vendor=?,status=?,payment_type=? WHERE invoice_id=?";
                NSMutableArray *invitemsArray=[[NSMutableArray alloc]initWithObjects:ID,Discount,Ttax,itemname,des,price,avegcost,Qty,Dept,Vendor,HoldStatus,paymentType,invoiceID, nil];
                [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertSQL withArguments:invitemsArray];
                
                insertSQL=nil;
                [invitemsArray removeAllObjects];
            }

        }
    }
    

    
    NSString *querySQL = [NSString stringWithFormat: @"SELECT item_id, discount,total_tax,item_name,item_desscription,price_you_charge,avg_cost,item_quantity,invoice_id,unique_id,created_timestamp,payment_type,in_department,in_vendor,store_id,status,employee,customer FROM invoice_items_table WHERE invoice_id='%@'",invoiceID];
    NSMutableArray *invitemsArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:invitemsArray];
   
    querySQL=nil;
    
    NSMutableDictionary *CategoryDict=[[NSMutableDictionary alloc]init];
    [CategoryDict setObject:invitemsArray forKey:@"fields"];
    NSDictionary *jsonDict = [NSDictionary dictionaryWithDictionary:CategoryDict];
    
    
    NSError *err;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:kNilOptions error:&err];
    
    NSString *str=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
    if(![generalDataObject  connectedToInternet]){
    
        NSString *insertSQL =@"insert into pending_queries (query_type,user_id,page_url,parameters,table_name,current_time) values(?,?,?,?,?,?)";
        NSMutableArray *pendingArray=[[NSMutableArray alloc]initWithObjects:@"UPDATE",[generalDataObject  userID],@"saveinfo.php?",str,@"invoice_items_table",[generalDataObject getsystemDatetime], nil];
        
        [[DataBaseManager dataBaseManager] executeRecordsWithQuery:insertSQL withArguments:pendingArray];
        
    }
    else if([generalDataObject  connectedToInternet]){
        
        if ([[generalDataObject  OriginalbaseURLstr] length]>0)
        {
            
           // // //NSLog(@"%@",str);
            NSString *string=[NSString stringWithFormat:@"%@saveinfo.php?tablename=invoice_items_table&systemtime=%@&userid=%@&sessionid=%@&data=%@&update=true",[generalDataObject  OriginalbaseURLstr],[[generalDataObject getsystemDatetime] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[generalDataObject  userID],[generalDataObject  deviceID],[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
            
            //// //NSLog(@"%@",str);
            
            NSURL *url=[NSURL URLWithString:string];
            NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
            //// //NSLog(@"%@",url);
            
            [request setHTTPMethod:@"POST"];
            [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
            //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
            
            
            
            InvoiceItemsConnection = [NSURLConnection connectionWithRequest:request delegate:self];
            
            [InvoiceItemsConnection start];
            url=nil,request=nil,string=nil;
            
        }
    }
    
    
    CategoryDict=nil,jsonData=nil,jsonDict=nil,str=nil;
    
//Invoice total data
    
    
    
    NSString *Invoicesql;
    
    if ([InvoiceCheckNo length]>0)
    {
         Invoicesql =@"UPDATE invoice_total_table SET total_amt=?,status=?,total_avgcost=?,total_profitt=?,payment_type=?,cheque_no=? WHERE invoice_id=?";
        
        NSMutableArray *intArray=[[NSMutableArray alloc]initWithObjects:GrandTotalstr,HoldStatus,TotalAvgStr,[NSString stringWithFormat:@"%.02f", totlaprofit],paymentType,InvoiceCheckNo,invoiceID, nil];
        [[DataBaseManager dataBaseManager]executeRecordsWithQuery:Invoicesql withArguments:intArray];
    }
    else
    {
         Invoicesql =@"UPDATE invoice_total_table SET total_amt=?,status=?,total_avgcost=?,total_profitt=?,payment_type=? WHERE invoice_id=?";
        NSMutableArray *intArray=[[NSMutableArray alloc]initWithObjects:GrandTotalstr,HoldStatus,TotalAvgStr,[NSString stringWithFormat:@"%.02f", totlaprofit],paymentType,invoiceID, nil];
        [[DataBaseManager dataBaseManager]executeRecordsWithQuery:Invoicesql withArguments:intArray];
    }
    
    
    
   
    
    Invoicesql=nil;
    NSString *querySQL2 = [NSString stringWithFormat: @"SELECT invoice_id,store_id,total_amt,status,payment_type,total_avgcost,total_profitt,unique_id,created_timestamp,holdid,employee,customer,cheque_no FROM invoice_total_table WHERE invoice_id='%@'",invoiceID];
    
    NSMutableArray *invtotalDataArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL2 resultsArray:invtotalDataArray];
    
    NSMutableDictionary *CategoryDict2=[[NSMutableDictionary alloc]init];
    [CategoryDict2 setObject:invtotalDataArray forKey:@"fields"];
    NSDictionary *jsonDict2 = [NSDictionary dictionaryWithDictionary:CategoryDict2];
    
    
    NSError *err2;
    
    NSData *jsonData2 = [NSJSONSerialization dataWithJSONObject:jsonDict2 options:kNilOptions error:&err2];
    
    NSString *str2=[[NSString alloc] initWithData:jsonData2 encoding:NSUTF8StringEncoding];
    
    if(![generalDataObject  connectedToInternet])
    {
    
        NSString *insertSQL =@"insert into pending_queries (query_type,user_id,page_url,parameters,table_name,current_time) values(?,?,?,?,?,?)";
        NSMutableArray *pendingArray=[[NSMutableArray alloc]initWithObjects:@"UPDATE",[generalDataObject  userID],@"saveinfo.php?",str2,@"invoice_total_table",[generalDataObject getsystemDatetime], nil];
        
        [[DataBaseManager dataBaseManager] executeRecordsWithQuery:insertSQL withArguments:pendingArray];
        
    }
    else if([generalDataObject  connectedToInternet])
    {
        if ([[generalDataObject  OriginalbaseURLstr] length]>0)
        {
            
           // // //NSLog(@"%@",str2);
            NSString *string=[NSString stringWithFormat:@"%@saveinfo.php?tablename=invoice_total_table&systemtime=%@&userid=%@&sessionid=%@&data=%@&update=true",[generalDataObject  OriginalbaseURLstr],[[generalDataObject getsystemDatetime] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[generalDataObject  userID],[generalDataObject  deviceID],[str2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
            
            
            
            NSURL *url=[NSURL URLWithString:string];
            NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
            //// //NSLog(@"%@",url);
            
            [request setHTTPMethod:@"POST"];
            [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
            //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
            
            
            
            InvoiceTotalConnection = [NSURLConnection connectionWithRequest:request delegate:self];
            
            [InvoiceTotalConnection start];
             url=nil,request=nil,string=nil;
        }
    }
     CategoryDict2=nil,jsonData2=nil,jsonDict2=nil,str2=nil;
    InvoiceCheckNo=@"";
    
}
-(void)CancelPrint
{
    NSArray *PrinterpopupViewArray = PrinterpopupView.subviews;
    for (int i = 0; i<[PrinterpopupViewArray count]; i++) {
        UIView *vi =[PrinterpopupViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *PrinterViewArray = PrinterView.subviews;
    for (int i = 0; i<[PrinterViewArray count]; i++) {
        UIView *vi =[PrinterViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [PrinterView removeFromSuperview],[PrinterpopupView removeFromSuperview];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
{
    
    if (alertView==ItemsDeleteAlert && buttonIndex==0){
        if ([HoldID length]>0){
          
        //Items DATA Code
             HoldStatus=@"void";
            [self UpdateInVoiceDataMethod];
            
            //[self SaveInvoiceDataMethod];
            
            [ItemNamesArray removeAllObjects];
            [ItemNosArray removeAllObjects];
            [QntysArray removeAllObjects];
            [pricesArray removeAllObjects];
            [SnosArray removeAllObjects];
            [TaxesArray removeAllObjects];
            [AvegCostsArray removeAllObjects];
            [DiscountsArray removeAllObjects];
            
            [ItemVendorArray removeAllObjects];
            [ItemDeptsArray removeAllObjects];
            [ItemDesArray removeAllObjects];
            
            [ProductslistTable reloadData];
                
            SubTDisplaylbl.text=@"$ 0.00";
            taxDlbl.text=@"$ 0.00";
            GTotalDlbl.text=@"$ 0.00";
            [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
            HoldID=@"";
            invoiceID=@"";
                
            
        }else if ([RecallInvoiceID length]>0){
            invoiceID=RecallInvoiceID;
             HoldStatus=@"void";
            [self UpdateInVoiceDataMethod];
           
           // [self SaveInvoiceDataMethod];
            
            [ItemNamesArray removeAllObjects];
            [ItemNosArray removeAllObjects];
            [QntysArray removeAllObjects];
            [pricesArray removeAllObjects];
            [SnosArray removeAllObjects];
            [TaxesArray removeAllObjects];
            [AvegCostsArray removeAllObjects];
            [DiscountsArray removeAllObjects];
            
            [ItemVendorArray removeAllObjects];
            [ItemDeptsArray removeAllObjects];
            [ItemDesArray removeAllObjects];
            
            [ProductslistTable reloadData];
            
            SubTDisplaylbl.text=@"$ 0.00";
            taxDlbl.text=@"$ 0.00";
            GTotalDlbl.text=@"$ 0.00";
            [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
            [PayBtn setTitle:@"Pay" forState:UIControlStateNormal];
            HoldID=@"";
            invoiceID=@"";
            RecallInvoiceID=@"";
        }else
        {
            HoldStatus=@"void";
            invoiceID=[generalDataObject  getDeviceID];
            
            [self SaveInvoiceDataMethod];

        [ItemNamesArray removeAllObjects];
        [ItemNosArray removeAllObjects];
        [QntysArray removeAllObjects];
        [pricesArray removeAllObjects];
        [SnosArray removeAllObjects];
        [TaxesArray removeAllObjects];
        [AvegCostsArray removeAllObjects];
        [DiscountsArray removeAllObjects];
        
        [ItemVendorArray removeAllObjects];
        [ItemDeptsArray removeAllObjects];
        [ItemDesArray removeAllObjects];
        
        [ProductslistTable reloadData];
         SubTDisplaylbl.text=@"$ 0.00";
         taxDlbl.text=@"$ 0.00";
         GTotalDlbl.text=@"$ 0.00";
         [retraiveOnHoldBtn setTitle:@"Fetch on Hold" forState:UIControlStateNormal];
            
        }
        itemcount=0;
        
    }else if (alertView==Changealert && buttonIndex==0){
        //[self PrinterViewMethod];
    
        if ([PrinterIpsArray count]>0){
            [self PrinterDataMethod];
        }
    }else if (alertView==DeleteInvoiceAlert && buttonIndex==0){
        NSString *holidid=[HoldIdsArray objectAtIndex:selectededInvoice];
        NSString *invoiceid=[InVoiceIdsArray objectAtIndex:selectededInvoice];
        
        NSString *updateSQL3 =@"DELETE FROM invoice_total_table WHERE invoice_id=?";
        NSMutableArray *deleteArray=[[NSMutableArray alloc]initWithObjects:invoiceid, nil];
        [[DataBaseManager dataBaseManager]executeRecordsWithQuery:updateSQL3 withArguments:deleteArray];
        
        NSString *updateSQL = @"DELETE FROM invoice_items_table WHERE invoice_id=?";
        
       [[DataBaseManager dataBaseManager]executeRecordsWithQuery:updateSQL withArguments:deleteArray];
        
        NSString *updateSQL2 =@"DELETE FROM printer_commands WHERE hold_id=?";
        NSMutableArray *holdArray=[[NSMutableArray alloc]initWithObjects:holidid, nil];
        [[DataBaseManager dataBaseManager]executeRecordsWithQuery:updateSQL2 withArguments:holdArray];
        
        NSArray *FetchOnHoldBackViewArray = FetchOnHoldBackView.subviews;
        for (int i = 0; i<[FetchOnHoldBackViewArray count]; i++) {
            UIView *vi =[FetchOnHoldBackViewArray objectAtIndex:i];
            [vi removeFromSuperview];
            vi = nil;
        }
        NSArray *FetchOnHoldViewArray = FetchOnHoldView.subviews;
        for (int i = 0; i<[FetchOnHoldViewArray count]; i++) {
            UIView *vi =[FetchOnHoldViewArray objectAtIndex:i];
            [vi removeFromSuperview];
            vi = nil;
        }
        [FetchOnHoldView removeFromSuperview],[FetchOnHoldBackView removeFromSuperview];
        [FecthOnHoldlistTable reloadData];
        updateSQL3=nil,updateSQL2=nil,updateSQL=nil;
    }
    
}
-(void)VoidinVoiceClicked
{
    

    if ([[generalDataObject  userType] isEqualToString:@"employee"])
    {
        if ([[generalDataObject  void_invoices_permission] isEqualToString:@"yes"]){
            
            if ([ItemNamesArray count]>0){
                ItemsDeleteAlert=[[UIAlertView alloc]initWithTitle:@"Delete All" message:@"Are you sure want to delete" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil];
                [ItemsDeleteAlert show];
            }else
            {
            
                
                 [self.view makeToast:@"Please Add The Items."];
            }
            
        }else{
            UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
            
            [authalert show];
            authalert=nil;
        }
    }else{
        
        if ([ItemNamesArray count]>0){
            
       ItemsDeleteAlert=[[UIAlertView alloc]initWithTitle:@"Delete All" message:@"Are you sure want to delete" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil];
       [ItemsDeleteAlert show];
            
            
        }else{
      
            [self.view makeToast:@"Please Add The Items."];
        }
    
    
    }

}
-(void)DeleteAllDataClicked
{
    
    if (RecallinvoiceValue==YES)
    {
        [DeleteBtn removeTarget:nil
                             action:NULL
                   forControlEvents:UIControlEventAllEvents];
    }
    else if (RecallinvoiceValue==NO)
    {
    if ([[generalDataObject  userType] isEqualToString:@"employee"])
    {
        if ([[generalDataObject  delete_items_permission] isEqualToString:@"yes"])
        {
            
            if ([ItemNamesArray count]>0){
                
                ItemsDeleteAlert=[[UIAlertView alloc]initWithTitle:@"Delete All" message:@"Are you sure want to delete" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil];
                [ItemsDeleteAlert show];
             
            } else{
                
                 [self.view makeToast:@"Please Add The Items."];
            }
          
        }else{
            UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
            
            [authalert show];
            authalert=nil;
        }
        
    }else{
        if ([ItemNamesArray count]>0){
            
            ItemsDeleteAlert=[[UIAlertView alloc]initWithTitle:@"Delete All" message:@"Are you sure want to delete" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil];
            [ItemsDeleteAlert show];
            
            
        }else
        {
            
             [self.view makeToast:@"Please Add The Items."];
            
        }
    }
 }
    
}
-(void)ItemsAddmethod
{

    CGFloat homewidth3=HomebackView.frame.size.width/2;
   // if (!itemsView)
    itemsView=[[UIScrollView alloc]init];
    itemsView.frame =CGRectMake(homewidth3+10+DepartmentsTable.frame.size.width+5,SubtotalView.frame.size.height+235,(homewidth3-10-156),HomebackView.frame.size.height-(SubtotalView.frame.size.height+240));
    itemsView.contentSize=CGSizeMake((homewidth3-10-156), 60*[ItemsArray count]);
    [itemsView setBackgroundColor:[UIColor clearColor]];
    [HomebackView addSubview:itemsView];
    
    ItemboolVlaue=YES;
    
    int btncount=0;
    int h=0;
    int w=0;
    CGFloat itemw=itemsView.frame.size.width/2;
    @autoreleasepool {
        for (int i=0; i<[ItemsArray count]; i++)
        {
            if (btncount==2){
                h=h+70;
                w=0;
                
                btncount=0;
            }
           
            ItemBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            ItemBtn.titleLabel.font=[UIFont systemFontOfSize:15.0f];
            [ItemBtn setTitle:[ItemsArray objectAtIndex:i] forState:UIControlStateNormal];
            [ItemBtn setBackgroundImage:[UIImage imageNamed:@"litebutton.png"] forState:UIControlStateNormal];
            ItemBtn.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
            ItemBtn.titleLabel.numberOfLines = 2;
            ItemBtn.frame=CGRectMake(w,h,itemw-10,60);
            ItemBtn.tag=i+100;
            [ItemBtn addTarget:self action:@selector(ItemClicked:) forControlEvents:UIControlEventTouchUpInside];
            [ItemBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [itemsView addSubview:ItemBtn];
            
            btncount=btncount+1;
            w=itemw;
            
        }

    }
}
-(void) modifierViewMethod
{
    if (!modifierPopupView)
    modifierPopupView=[[UIView alloc]init];
    if (isLandScope) {
        modifierPopupView.frame=CGRectMake(0, 0, 1024, 768);
    }
    
    else{
        
        modifierPopupView.frame=CGRectMake(0, 0, 768, 1024);
    }
    [modifierPopupView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:modifierPopupView];
     if (!modifieView)
    modifieView=[[UIView alloc]init];
    if (isLandScope){
        modifieView.frame=CGRectMake(225, 50, modifierPopupView.frame.size.width-450, modifierPopupView.frame.size.height-100);
       
    }else{
        modifieView.frame=CGRectMake(150, 200, modifierPopupView.frame.size.width-300, modifierPopupView.frame.size.height-400);
    }
    
    [modifieView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    //[Discountview setBackgroundColor:[UIColor blackColor]];
    
    [modifieView.layer setBorderWidth:2.0];
    [modifieView.layer setBorderColor:[[UIColor whiteColor] CGColor]];
    //AddvendorsView.layer.cornerRadius=8;
    [modifierPopupView addSubview:modifieView];
    modifierBoolValue=YES;
    int btncount=0;
    int h=20;
    int w=5;
    CGFloat itemw=modifieView.frame.size.width/2;
    for (int i=0; i<[modifierItemsArray count]; i++)
    {
        if (btncount==2){
            h=h+70;
            w=5;
            
            btncount=0;
        }
        
        modifierItem_Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        modifierItem_Button.titleLabel.font=[UIFont systemFontOfSize:15.0f];
        [modifierItem_Button setTitle:[modifierItemsArray objectAtIndex:i] forState:UIControlStateNormal];
        [modifierItem_Button setBackgroundImage:[UIImage imageNamed:@"litebutton.png"] forState:UIControlStateSelected];
        [modifierItem_Button setBackgroundImage:[UIImage imageNamed:@"lightgreenbutton.png"] forState:UIControlStateNormal];
        modifierItem_Button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
        modifierItem_Button.titleLabel.numberOfLines = 2;
        modifierItem_Button.frame=CGRectMake(w,h,itemw-10,60);
        modifierItem_Button.tag=i+100;
        [modifierItem_Button addTarget:self action:@selector(modifierItemClicked:) forControlEvents:UIControlEventTouchUpInside];
        
        [modifierItem_Button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [modifieView addSubview:modifierItem_Button];
        
        btncount=btncount+1;
        w=itemw;
     
    }
     CGFloat modifierW=modifieView.frame.size.width/2;
    @autoreleasepool {
        okmodifier_Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        okmodifier_Button.frame=CGRectMake(modifierW-100, 550, 80, 40);
        [okmodifier_Button addTarget:self action:@selector(okmodifierView) forControlEvents:UIControlEventTouchUpInside];
        [okmodifier_Button setTitle:@"OK" forState:UIControlStateNormal];
        [okmodifier_Button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [okmodifier_Button setBackgroundImage:[UIImage imageNamed:@"okay-button.png"] forState:UIControlStateNormal];
        [modifieView addSubview:okmodifier_Button];
        
        cancelmodifier_Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        cancelmodifier_Button.frame=CGRectMake(okmodifier_Button.frame.size.width+modifierW-60, 550, 80, 40);
        [cancelmodifier_Button addTarget:self action:@selector(CancelmodifierView) forControlEvents:UIControlEventTouchUpInside];
        [cancelmodifier_Button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [cancelmodifier_Button setBackgroundImage:[UIImage imageNamed:@"okay-button.png"] forState:UIControlStateNormal];
        [cancelmodifier_Button setTitle:@"Cancel" forState:UIControlStateNormal];
        [modifieView addSubview:cancelmodifier_Button];
    }
  
   
     selectedModifieritemsArray=[[NSMutableArray alloc]init];
    
}
-(void)modifierItemClicked:(UIButton *)sender
{
   sender.selected=YES;
      NSInteger selected=sender.tag-100;
       NSString *item=[modifierItemsArray objectAtIndex:selected];
      [selectedModifieritemsArray addObject:item];
    
}
-(void)CancelmodifierView
{
    NSArray *modifierPopupViewArray = modifierPopupView.subviews;
    for (int i = 0; i<[modifierPopupViewArray count]; i++) {
        UIView *vi =[modifierPopupViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *modifieViewArray = modifieView.subviews;
    for (int i = 0; i<[modifieViewArray count]; i++) {
        UIView *vi =[modifieViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [modifieView removeFromSuperview];
    [modifierPopupView removeFromSuperview];
       modifierPopupView=nil,modifieView=nil;
}
-(void)okmodifierView
{
    NSArray *modifierPopupViewArray = modifierPopupView.subviews;
    for (int i = 0; i<[modifierPopupViewArray count]; i++) {
        UIView *vi =[modifierPopupViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *modifieViewArray = modifieView.subviews;
    for (int i = 0; i<[modifieViewArray count]; i++) {
        UIView *vi =[modifieViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [modifieView removeFromSuperview];
    [modifierPopupView removeFromSuperview];
    modifierPopupView=nil,modifieView=nil;
    
    for (int i=0; i<[selectedModifieritemsArray count]; i++)
    {
    NSString *item=[selectedModifieritemsArray objectAtIndex:i];
   
        [self itemclickmethod:item];
  }
    [ProductslistTable reloadData];
    [self GetTotalAmountMethod];
    
    [selectedModifieritemsArray removeAllObjects],selectedModifieritemsArray=nil;
}
-(void)ItemClicked:(UIButton *)sender
{
   
    modifierItemsArray=[[NSMutableArray alloc]init];
   
    if (RecallinvoiceValue==YES)
    {
        [ItemBtn removeTarget:nil
                        action:NULL
              forControlEvents:UIControlEventAllEvents];
    }
    else if (RecallinvoiceValue==NO)
    {
    [retraiveOnHoldBtn setTitle:@"Save on Hold" forState:UIControlStateNormal];
        NSInteger selected=sender.tag-100;
        NSString *item=[ItemsArray objectAtIndex:selected];
         NSString *moditem=[productnosArray objectAtIndex:selected];
       
     NSString *modquerySQL = [NSString stringWithFormat: @"SELECT modifier_item_no,inventary_item_name FROM modifier_table WHERE inventory_item_no='%@'",moditem];
        NSMutableArray *modifiersArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:modquerySQL resultsArray:modifiersArray];
        
        if ([modifiersArray count]>0)
        {
            for (NSDictionary *myDict in modifiersArray)
            {
                [modifierItemsArray addObject:[myDict objectForKey:@"inventary_item_name"]];
            }
            [self modifierViewMethod];
            
        }else{
            
            [self itemclickmethod:item];
         [ProductslistTable reloadData];
         [self GetTotalAmountMethod];
   
    }
       
    }
    
}
-(void)itemclickmethod:(NSString *)item
{
    NSString *querySQL = [NSString stringWithFormat:@"SELECT inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventory_total_tax,inventary_taxone,inventary_vendor FROM inventorytable WHERE inventary_item_name='%@'",item];
    NSMutableArray *productDataArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:productDataArray];
    @autoreleasepool {
        for (NSDictionary *myDict in productDataArray)
        {
            NSString *itemstr=[myDict objectForKey:@"inventary_item_name"];
            
            if ([itemstr isEqualToString:item]){
                NSString *itemno=[myDict objectForKey:@"inventory_item_no"];
                NSString *Qty=[myDict objectForKey:@"inventary_quantity"];
                NSString *price=[myDict objectForKey:@"inventary_price_change"];
                
                if ([ItemNosArray count]>0){
                    NSUInteger objIdx = [ItemNosArray containsObject:itemno];
                    //// //NSLog(@"%lu",(unsigned long)objIdx);
                    if(objIdx == 0)
                    {
                        [ItemNosArray addObject:[myDict objectForKey:@"inventory_item_no"]];
                        [ItemNamesArray addObject:[myDict objectForKey:@"inventary_item_name"]];
                        [QntysArray addObject:[myDict objectForKey:@"inventary_quantity"]];
                        [pricesArray addObject:[myDict objectForKey:@"inventary_price_change"]];
                        [TaxesArray addObject:[myDict objectForKey:@"inventory_total_tax"]];
                        [AvegCostsArray addObject:[myDict objectForKey:@"inventary_avg_cost"]];
                        [DiscountsArray addObject:@"0"];
                        
                        [ItemVendorArray addObject:[myDict objectForKey:@"inventary_vendor"]];
                        [ItemDeptsArray addObject:[myDict objectForKey:@"inventary_department"]];
                        [ItemDesArray addObject:[myDict objectForKey:@"inventary_second_description"]];
                        [SnosArray addObject:[NSString stringWithFormat:@"%d",[ItemNamesArray count]]];
                    }else{
                        NSInteger qindex=[ItemNosArray indexOfObject:itemno];
                        NSString *anotherqty=[QntysArray objectAtIndex:qindex];
                        NSString *anotherprice=[pricesArray objectAtIndex:qindex];
                        
                        quantity=[anotherqty intValue]+[Qty intValue];
                        Pricevalue=[anotherprice doubleValue]+[price doubleValue];
                        [QntysArray removeObjectAtIndex:qindex];
                        [pricesArray removeObjectAtIndex:qindex];
                        [QntysArray insertObject:[NSString stringWithFormat:@"%d",quantity] atIndex:qindex];
                        [pricesArray insertObject:[NSString stringWithFormat:@"%0.02f",Pricevalue] atIndex:qindex];
                        anotherqty=nil,anotherprice=nil;
                    }
                }else{
                    
                    [ItemNosArray addObject:[myDict objectForKey:@"inventory_item_no"]];
                    [ItemNamesArray addObject:[myDict objectForKey:@"inventary_item_name"]];
                    [QntysArray addObject:[myDict objectForKey:@"inventary_quantity"]];
                    [pricesArray addObject:[myDict objectForKey:@"inventary_price_change"]];
                    [TaxesArray addObject:[myDict objectForKey:@"inventory_total_tax"]];
                    [AvegCostsArray addObject:[myDict objectForKey:@"inventary_avg_cost"]];
                    [DiscountsArray addObject:@"0"];
                    
                    [ItemVendorArray addObject:[myDict objectForKey:@"inventary_vendor"]];
                    [ItemDeptsArray addObject:[myDict objectForKey:@"inventary_department"]];
                    [ItemDesArray addObject:[myDict objectForKey:@"inventary_second_description"]];
                    [SnosArray addObject:[NSString stringWithFormat:@"%d",[ItemNosArray count]]];
                }
                itemno=nil,Qty=nil,price=nil;
            }
            itemstr=nil;
        }
    }
}
-(void)GetTotalAmountMethod
{
    int count=0;
    if ([pricesArray count]>0){
        for (int i=0; i<[pricesArray count]; i++)
        {
            NSString *price=[pricesArray objectAtIndex:i];
            NSString *tax=[TaxesArray objectAtIndex:i];
              NSString *aveg=[AvegCostsArray objectAtIndex:i];
            double pricevalue=[price doubleValue];
            count=count+1;
            if (count>1){
                SubtotalValue=SubtotalValue+pricevalue;
                TaxValue=TaxValue+(([tax doubleValue]*pricevalue)/100);
                Grandvalue=SubtotalValue+TaxValue;
                TotalAvegCost=TotalAvegCost+[aveg doubleValue];
            }else{
                SubtotalValue=pricevalue;
                 TaxValue=(([tax doubleValue]*pricevalue)/100);
                Grandvalue=SubtotalValue+TaxValue;
                
                 TotalAvegCost=[aveg doubleValue];
            }
            tax=nil,price=nil,aveg=nil;
            //// //NSLog(@"%f",SubtotalValue);
        }
        SubTotalstr = [NSString stringWithFormat:@"%@%.02f", @"$ ",SubtotalValue];
        TaxValueStr = [NSString stringWithFormat:@"%@%.02f", @"$ ",TaxValue];
        GrandTotalstr=[NSString stringWithFormat:@"%@%.02f",@"$ ",Grandvalue];
         TotalAvgStr=[NSString stringWithFormat:@"%.02f", TotalAvegCost];

        taxDlbl.text=TaxValueStr;
        SubTDisplaylbl.text=SubTotalstr;
        GTotalDlbl.text=GrandTotalstr;
      

    }else{
          SubTDisplaylbl.text=@"$ 0.00";
        taxDlbl.text=@"$ 0.00";
        
        GTotalDlbl.text=@"$ 0.00";
        
    }
    
}
- (void)longPress:(UILongPressGestureRecognizer*)gesture
{
    if ( gesture.state == UIGestureRecognizerStateEnded)
    {
        //// //NSLog(@"Long Press");
    }
}
- (BOOL)shouldAutorotate
{
    return YES;
    
    
}
-(void)updateUI
{
    
    if (isLandScope)
    {
        
        CGFloat width,height;
       
        width=1024;
        height=748;
        backgroundcolorview.frame=CGRectMake(0,y,width,height-100);
    
       
       //  sidemenu.frame=CGRectMake(0, 1,170 ,height-150);
       //sidemenu.hidden=YES;
        
        [categorybutton setFrame:CGRectMake(0.0,p,170,40)];
         navBar.frame=CGRectMake(0, 0,width , 50.0);
        
        [logoBtn setFrame:CGRectMake(60,0,250,50)];
        sationLbl.frame=CGRectMake(navBar.frame.size.width-280, 5,100, 40);
        EmpIdlbl.frame=CGRectMake(navBar.frame.size.width-193, 5,150, 40);
        Timelbl.frame=CGRectMake(navBar.frame.size.width-62, 6,80, 40);
        
        
        
       // mainview.frame=CGRectMake(sidemenu.frame.size.width+10,0,width-(sidemenu.frame.size.width+20),height-150);
     mainview.frame=CGRectMake(10,50,width-20,height-160);
        
        [backgroundcolorview addSubview:mainview];
       [menubutton setFrame:CGRectMake(0,0,50,50)];
        maintoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
       
        logoimageview.frame=CGRectMake(50, (backgroundcolorview.frame.size.height)+5+y,(height-(backgroundcolorview.frame.size.height)-30), (height-(backgroundcolorview.frame.size.height)-30));
        
        [helpiconButton setFrame:CGRectMake(width-180,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
        
        [logouticonButton setFrame:CGRectMake(width-100,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
        Modelbl.frame=CGRectMake(20,400,60, 30);
       
        Myswitch.frame=CGRectMake(Modelbl.frame.size.width+20,400,100,40);
        
  //home View
        
        HomebackView.frame=CGRectMake(0, 5,mainview.frame.size.width, mainview.frame.size.height-10);
        
     
        CGFloat homewidth=(HomebackView.frame.size.width/2);
        CGFloat btnw=homewidth/2;
      
         ProductscanBtn.frame=CGRectMake(0,5,btnw,40);
        ProductscanField.frame=CGRectMake(0,5,btnw,40);
        
      
        //ProductscanField.frame=CGRectMake(0,52,btnw-50, 40);
      
        Quantitybtn.frame=CGRectMake(ProductscanBtn.frame.size.width+10,5,btnw-100, 40);
       
        QantyField.frame=CGRectMake(ProductscanBtn.frame.size.width+5,5,btnw-180,40);
      
        QtyGobtn.frame=CGRectMake(ProductscanBtn.frame.size.width+QantyField.frame.size.width+12,5,40, 40);
       
        SearchBtn.frame=CGRectMake(ProductscanBtn.frame.size.width+20+QantyField.frame.size.width+40,5,btnw-130, 40);
        
        tablestripview.frame=CGRectMake(0,60,homewidth,30);
    
        CGFloat sw=tablestripview.frame.size.width/5;
    
        snolbl.frame=CGRectMake(0,0, sw-30, 30);
        itemlbl.frame=CGRectMake(snolbl.frame.size.width,0, sw+50, 30);
       
        iteminfolbl.frame=CGRectMake(snolbl.frame.size.width+itemlbl.frame.size.width,0, sw+60, 30);
      
        qntylbl.frame=CGRectMake(snolbl.frame.size.width+itemlbl.frame.size.width+iteminfolbl.frame.size.width-40,0, sw-10, 30);
      
        pricelbl.frame=CGRectMake(snolbl.frame.size.width+itemlbl.frame.size.width+iteminfolbl.frame.size.width+qntylbl.frame.size.width-70,0, sw-20, 30);
      
        
        
            ProductslistTable.frame = CGRectMake(0, 90,homewidth,330);
       
        
            //ProductslistTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 130,homewidth,530) style:UITableViewStylePlain];
            
        CGFloat deW=ProductslistTable.frame.size.width/5;
        DeleteBtn.frame=CGRectMake(0,95+ProductslistTable.frame.size.height,deW-20, 40);
        
        DiscountBtn.frame=CGRectMake(DeleteBtn.frame.size.width+5,95+ProductslistTable.frame.size.height,deW-10, 40);
        
        QuantyChangeBtn.frame=CGRectMake(DeleteBtn.frame.size.width+5+DiscountBtn.frame.size.width+10,95+ProductslistTable.frame.size.height,deW+60, 40);
        
       
        PriceChangeBtn.frame=CGRectMake(DeleteBtn.frame.size.width+5+QuantyChangeBtn.frame.size.width+10+DiscountBtn.frame.size.width+10,95+ProductslistTable.frame.size.height,deW+20, 40);
        
       
        
        custBackview.frame=CGRectMake(0, 140+ProductslistTable.frame.size.height,homewidth,HomebackView.frame.size.height-(140+ProductslistTable.frame.size.height));
        
       
        //CGFloat homewidth=(tablestripview.frame.size.width/2);
        CGFloat Cw=custBackview.frame.size.width/4;
        CGFloat CH=custBackview.frame.size.height/2;
      
        AddBtn.frame=CGRectMake(0,140+ProductslistTable.frame.size.height,Cw-20, CH);
        
        FindBtn.frame=CGRectMake(0,140+ProductslistTable.frame.size.height+CH,Cw-20, CH);
        
        CustomerBtn.frame=CGRectMake(AddBtn.frame.size.width,140+ProductslistTable.frame.size.height+2,Cw, 40);
        CustomerinflBtn.frame=CGRectMake(AddBtn.frame.size.width+CustomerBtn.frame.size.width,140+ProductslistTable.frame.size.height+2,Cw+20, 40);
        
        
        Customernamelbl.frame=CGRectMake(FindBtn.frame.size.width,140+ProductslistTable.frame.size.height+2+CustomerBtn.frame.size.height+5,Cw+Cw+100, 30);
      
        CustomerNolbl.frame=CGRectMake(FindBtn.frame.size.width,140+ProductslistTable.frame.size.height+2+CustomerBtn.frame.size.height+Customernamelbl.frame.size.height+10,Cw+Cw+100, 30);
        
        SubtotalView.frame=CGRectMake(homewidth+10,0,homewidth-10,100);
        
       
        //CGFloat homewidth=(tablestripview.frame.size.width/2);
        CGFloat subW=SubtotalView.frame.size.width/2;
        
       
        Subtlbl.frame=CGRectMake(5,5,subW,30);
       
        SubTDisplaylbl.frame=CGRectMake(subW+80,0,subW,30);
        Taxlbl.frame=CGRectMake(5,60,subW,30);
        taxDlbl.frame=CGRectMake(subW+80,60,subW,30);
        
        blackstripview.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height,homewidth-10,2);
        GrandtotalView.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height+2,homewidth-10,40);
        
        CGFloat GW=GrandtotalView.frame.size.width/2;
      
        GrandTlbl.frame=CGRectMake(5,5,GW,30);
        
        GTotalDlbl.frame=CGRectMake(subW+80,5,GW,30);
        
        CGFloat Vwidth=homewidth/2;
       
        PayBtn.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height+45,Vwidth-10, 50);
        
        retraiveOnHoldBtn.frame=CGRectMake(homewidth+10+PayBtn.frame.size.width+10,SubtotalView.frame.size.height+45,Vwidth-10, 50);
        PrintLastInvcBtn.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height+100,Vwidth-10, 40);
        RecallBtn.frame=CGRectMake(homewidth+20+PrintLastInvcBtn.frame.size.width,SubtotalView.frame.size.height+100,Vwidth-10, 40);
        
        VoidInVoiceBtn.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height+145,Vwidth-10, 40);
        
        SplitInvoiceBtn.frame=CGRectMake(homewidth+20+VoidInVoiceBtn.frame.size.width,SubtotalView.frame.size.height+145,Vwidth-10, 40);
        
        
        CGFloat Cashwidth=homewidth/3;
        CheckBtn.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height+190,Cashwidth-10, 40);
    
        CashBtn.frame=CGRectMake(homewidth+20+CheckBtn.frame.size.width,SubtotalView.frame.size.height+190,Cashwidth-10, 40);
        
        CreditBtn.frame=CGRectMake(homewidth+20+CheckBtn.frame.size.width+CashBtn.frame.size.width+10,SubtotalView.frame.size.height+190,Cashwidth-10, 40);
        
        
        DepartmentsTable.frame = CGRectMake(homewidth+10, SubtotalView.frame.size.height+235,156,HomebackView.frame.size.height-(SubtotalView.frame.size.height+240));
        
        
        CGFloat homewidth3=HomebackView.frame.size.width/2;
        itemsView.frame =CGRectMake(homewidth3+10+DepartmentsTable.frame.size.width+5,SubtotalView.frame.size.height+235,(homewidth3-10-156),HomebackView.frame.size.height-(SubtotalView.frame.size.height+240));
        
     itemsView.contentSize=CGSizeMake((homewidth3-10-156),60*[ItemsArray count]);
        
        
  //table view
        
        
        namelbl.frame=CGRectMake(0, 0, 30,100);
        taxlbl.frame=CGRectMake(50,0,120,100);
        stock.frame=CGRectMake(170,0,160,100);
        Deslbl.frame=CGRectMake(340,0,30,100);
        Vendorlbl.frame=CGRectMake(390,0,60,100);
       

        [DeleteItemBtn setFrame:CGRectMake(460, 10, 25, 25)];
        
        
        
//Search Button  view
        
        SearchViewpopup.frame=CGRectMake(0, 0, 1024, 768);
  
        
       // SearchViewpopup.frame=CGRectMake(0, 0, 768, 1024);
       
    SearchView.frame=CGRectMake(20, 40, SearchViewpopup.frame.size.width-40, SearchViewpopup.frame.size.height-80);
    SearchView.contentSize=CGSizeMake(SearchViewpopup.frame.size.width-40, SearchViewpopup.frame.size.height+300);
   
    
    SearchlistTable.frame = CGRectMake(0,0, SearchView.frame.size.width,SearchView.frame.size.height-100);

    
    CGFloat SearchW=(SearchView.frame.size.width-20)/7;
    Catlbl.frame=CGRectMake(10,SearchlistTable.frame.size.height+25,SearchW-15,40);
  
    
    CatBtn.frame=CGRectMake(Catlbl.frame.size.width+10,SearchlistTable.frame.size.height+25,SearchW+15,40);
   
    Deptlbl.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+5,SearchlistTable.frame.size.height+25,SearchW+15, 40);
   
    DeptBtn.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+5,SearchlistTable.frame.size.height+25,SearchW+15, 40);
   
    SearchField.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+DeptBtn.frame.size.width+15,SearchlistTable.frame.size.height+25,SearchW+15, 40);
  
    
 ItemsDataTable.frame = CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+DeptBtn.frame.size.width+15,SearchlistTable.frame.size.height+25+40,SearchW+15, 100) ;
   
    
    Gobtn.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+DeptBtn.frame.size.width+SearchField.frame.size.width+20,SearchlistTable.frame.size.height+25,40, 40);
   
    
    CancelItemBtn.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+DeptBtn.frame.size.width+SearchField.frame.size.width+Gobtn.frame.size.width+25,SearchlistTable.frame.size.height+25,SearchW, 40);

 //Category View
        
        Pcategorypopup.frame=CGRectMake(0, 0, 1024, 768);
       // Pcategorypopup.frame=CGRectMake(0, 0, 768, 1024);
 
    PCategorysTable.frame=CGRectMake(100,200 ,Pcategorypopup.frame.size.width-200, Pcategorypopup.frame.size.height-400);

 //Department
        
        Pdeaprtmentpopup.frame=CGRectMake(0, 0, 1024, 768);
       // Pdeaprtmentpopup.frame=CGRectMake(0, 0, 768, 1024);
    PdepartmentsTable.frame=CGRectMake(100,200 ,Pdeaprtmentpopup.frame.size.width-200, Pdeaprtmentpopup.frame.size.height-400);
        
//Search data table view
        
          Snolbl.frame=CGRectMake(0, 0, 50, 40);
        itemnolbl.frame=CGRectMake(50, 0, 200, 60);
        Itemnamelbl.frame=CGRectMake(200, 0, 200, 60);
        
        Ppricelbl.frame=CGRectMake(400, 0, 150, 60);
        Instock.frame=CGRectMake(550, 0, 150, 60);
        
        Pdeslbl.frame=CGRectMake(700, 0, 130, 60);
      
        vendornolbl.frame=CGRectMake(830, 0, 150, 60);
        
 //Change Quantity View
        
        QuantityPopupView.frame=CGRectMake(0, 0, 1024, 768);
    
        //QuantityPopupView.frame=CGRectMake(0, 0, 768, 1024);
   
    
        Quantityview.frame=CGRectMake(200, 200, QuantityPopupView.frame.size.width-400, QuantityPopupView.frame.size.height-450);
   
       // Quantityview.frame=CGRectMake(150, 300, QuantityPopupView.frame.size.width-300, QuantityPopupView.frame.size.height-750);
    

    
    CGFloat instwidth=(Quantityview.frame.size.width)/2;
    CGFloat inst=instwidth/2;
        
        QTextlbl.frame=CGRectMake(10, 25,Quantityview.frame.size.width-20, 50);
        
        ChangeQuantityField.frame=CGRectMake(20, 95,instwidth+50, 40);
        
        SaveQtyBtn.frame=CGRectMake(ChangeQuantityField.frame.size.width+40, 105, 80, 30);
    
        PrintatDeptlbl.frame=CGRectMake(inst-60,160,instwidth+20, 50);
        PrintDeptSwitch.frame=CGRectMake(PrintatDeptlbl.frame.size.width+60,172,100,40);
        Swicthtextlbl.frame=CGRectMake(PrintatDeptlbl.frame.size.width+60,210,100,40);
        
//Change Price View
        
        PricePopupView.frame=CGRectMake(0, 0, 1024, 768);

       // PricePopupView.frame=CGRectMake(0, 0, 768, 1024);
        Priceview.frame=CGRectMake(200, 200, PricePopupView.frame.size.width-400, PricePopupView.frame.size.height-450);
   
       // Priceview.frame=CGRectMake(150, 300, PricePopupView.frame.size.width-300, PricePopupView.frame.size.height-750);
  
    
    
    CGFloat Pricewidth=(Priceview.frame.size.width)/2;
    CGFloat pricew=Pricewidth/2;
    
    
    PriceTextlbl.frame=CGRectMake(pricew-60, 25,Pricewidth, 50);
 
    ChangePriceField.frame=CGRectMake(pricew-20, 95,Pricewidth+50, 40);
   SavePriceBtn.frame=CGRectMake(Pricewidth-90, 180, 80, 30);
   CancelPriceBtn.frame=CGRectMake(Pricewidth+40, 180, 80, 30);
 
        
 //Pay view
        
        PaypopupView.frame=CGRectMake(0, 0, 1024, 768);
        
        
        //PaypopupView.frame=CGRectMake(0, 0, 768, 1024);
    
  
        PayView.frame=CGRectMake(225, 50, PaypopupView.frame.size.width-450, PaypopupView.frame.size.height-100);
        
        //PayView.contentSize=CGSizeMake(PaypopupView.frame.size.width-450, PaypopupView.frame.size.height+100);
   
       // PayView.frame=CGRectMake(150, 200, PaypopupView.frame.size.width-300, PaypopupView.frame.size.height-400);
  
    
    CGFloat payw=PayView.frame.size.width/2;
    
  
        Amountlbl.frame=CGRectMake(20, 10,payw, 40);
        
        AmountField.frame=CGRectMake(20, 50,payw-30, 40);
      
        GivenAmountlbl.frame=CGRectMake(20, 100,payw, 40);
        GivenAmountField.frame=CGRectMake(20, 150,payw-30, 40);
        [DeleteGivenAmntBtn setFrame:CGRectMake(GivenAmountField.frame.size.width-30,8, 25, 25)];
      
        Paytypelbl.frame=CGRectMake(20, 200,payw, 40);
       
        
        CashDropDown.frame=CGRectMake(20,250,payw-20,40);
        
        CashlistTable .frame=CGRectMake(20,290,payw-20,100) ;
        
      SplitInvoiceTable.frame = CGRectMake(Amountlbl.frame.size.width, 60,payw-10, 180);
        
        //CashDropDown.frame=CGRectMake(payw-90,250,payw-20,40);
    
      // CashlistTable .frame=CGRectMake(payw-90,290,payw-20,100);
      
        SelectPrinterlabel.frame=CGRectMake(20, 200,payw, 40);

        SelectPrinterBtn.frame=CGRectMake(20,250,payw-20,40);
        
        PayPrinterDataTable .frame= CGRectMake(20,290,payw-20,100) ;
        
        SelectPrinterlabel.frame=CGRectMake(Amountlbl.frame.size.width+10, 200,payw, 40);
        
      
        PrinterSwitch.frame=CGRectMake(Amountlbl.frame.size.width-30+Amountlbl.frame.size.width/2,255,100,40);
        


    CGFloat cashw=PayView.frame.size.width/6;
      CGFloat Wd=12;
    for (int i=0; i<6; i++)
    {
       
       
        UIButton *mybtn=(UIButton *)[PayView viewWithTag:i+100];
        mybtn.frame=CGRectMake(Wd,450,cashw-10,40);
        [PayView addSubview:mybtn];
        
        Wd=Wd+cashw-5;
        
        
    }
    
    SavePayBtn.frame=CGRectMake(payw-100, 550, 80, 40);
  
    
    CancelPayBtn.frame=CGRectMake(SavePayBtn.frame.size.width+payw-60, 550, 80, 40);
  
        
//Printer View
        
        PrinterpopupView.frame=CGRectMake(0, 0, 1024, 768);
   
        
       // PrinterpopupView.frame=CGRectMake(0, 0, 768, 1024);
    
        PrinterView.frame=CGRectMake(200, 200, PrinterpopupView.frame.size.width-400, PrinterpopupView.frame.size.height-400);
   
       // PrinterView.frame=CGRectMake(150, 300, PrinterpopupView.frame.size.width-300, PrinterpopupView.frame.size.height-700);
   
    
    
    CGFloat instwidth2=(PrinterView.frame.size.width)/2;
    CGFloat inst2=instwidth2/2;
    
    textlbl.frame=CGRectMake(inst2, 5,instwidth2, 40);
    
    selectprinterlbl.frame=CGRectMake(inst2-60, 45,instwidth2, 40);
  
    
    SelectPrintBtn.frame=CGRectMake(inst2-20, 95,instwidth2+50, 40);
    
    PrinterDataTable.frame =CGRectMake(inst2-20, 135,instwidth2+50, 100);
    YesPrintBtn.frame=CGRectMake(instwidth2-90, 280, 80, 30);
    
    NoPrintBtn.frame=CGRectMake(instwidth2+40, 280, 80, 30);
        
 
//Customer View
       
    CustomerViewpopup.frame=CGRectMake(0, 0, 1024, 768);
  
        
       // CustomerViewpopup.frame=CGRectMake(0, 0, 768, 1024);
  
    
    CustomerView.frame=CGRectMake(20, 40, CustomerViewpopup.frame.size.width-40, CustomerViewpopup.frame.size.height-80);
        
    CustomerView.contentSize=CGSizeMake(CustomerViewpopup.frame.size.width-40, CustomerViewpopup.frame.size.height+300);
  
    
    
    CustomerlistTable .frame= CGRectMake(0,0, CustomerView.frame.size.width,CustomerView.frame.size.height-100);
    
  
    CustomerSearchField.frame=CGRectMake(20,CustomerlistTable.frame.size.height+25,250, 40);
    
    CustomerDataTable.frame= CGRectMake(20,CustomerlistTable.frame.size.height+25+40,250, 100);
    CustomerGobtn.frame=CGRectMake(CustomerSearchField.frame.size.width+30,CustomerlistTable.frame.size.height+25,40, 40);
  
    CustomerCancelBtn.frame=CGRectMake(CustomerSearchField.frame.size.width+30+CustomerGobtn.frame.size.width+10,CustomerlistTable.frame.size.height+25,100, 40);
    
 
 //Fetch on data View
        
        FetchOnHoldBackView.frame=CGRectMake(0, 0, 1024, 768);
        
        //FetchOnHoldBackView.frame=CGRectMake(0, 0, 768, 1024);
   
    
    FetchOnHoldView.frame=CGRectMake(20,100, FetchOnHoldBackView.frame.size.width-40, FetchOnHoldBackView.frame.size.height-200);
    
    CGFloat Fwidth=(FetchOnHoldView.frame.size.width)/2;
    
   
    Fetchlbl.frame=CGRectMake(Fwidth-60, 25,Fwidth, 50);

    FecthOnHoldlistTable.frame = CGRectMake(0,100, FetchOnHoldView.frame.size.width,FetchOnHoldView.frame.size.height-100);
       
 //Printer product view
        
        ProductPrinterPopUp.frame=CGRectMake(0, 0, 1024, 768);
   
      //  ProductPrinterPopUp.frame=CGRectMake(0, 0, 768, 1024);
  
    
    ProductPrinterView.frame=CGRectMake(20, 100, ProductPrinterPopUp.frame.size.width-40, ProductPrinterPopUp.frame.size.height-200);
   
    ProductPrinterView.contentSize=CGSizeMake(ProductPrinterPopUp.frame.size.width-40, ProductPrinterPopUp.frame.size.height+300);
    
    CGFloat changeProductfieldwidth=(ProductPrinterView.frame.size.width)/2;
    
    
 
    PrintTextlbl.frame=CGRectMake(changeProductfieldwidth-180, 10,changeProductfieldwidth, 30);
    
    ProductPrintertable .frame= CGRectMake(10,60, ProductPrinterView.frame.size.width-20,ProductPrinterView.frame.size.height-300);
    SavePrintBtn.frame=CGRectMake(changeProductfieldwidth-80,ProductPrinterView.frame.size.height-100 , 80, 30);

    CancelPrintBtn.frame=CGRectMake(changeProductfieldwidth+40, ProductPrinterView.frame.size.height-100 , 80, 30);
 
   
  //Store data View
    
        StoresPopupView.frame=CGRectMake(0, 0, 1024, 768);
   
        
       // StoresPopupView.frame=CGRectMake(0, 0, 768, 1024);
   
        StoresView.frame=CGRectMake(100, 200, StoresPopupView.frame.size.width-200, StoresPopupView.frame.size.height-400);
   
        //StoresView.frame=CGRectMake(50, 300, StoresPopupView.frame.size.width-100, StoresPopupView.frame.size.height-600);
   
    
    CGFloat widthfield4=(StoresView.frame.size.width)/4;
 
    SelectStorelbl.frame=CGRectMake(20,20,widthfield4,40);
   
    
    SelectStoreBtn.frame=CGRectMake(SelectStorelbl.frame.size.width+20, 20,widthfield4+10, 40);
 
    StoresListTable.frame = CGRectMake(SelectStorelbl.frame.size.width+20, 60,widthfield4+10, 100);
    ProceedStoreBtn.frame=CGRectMake(widthfield4+120,300,80,30);
        
//Product scan View

        ProductscanBackView.frame=CGRectMake(0, 0, 1024, 768);
        
        //ProductscanBackView.frame=CGRectMake(0, 0, 768, 1024);
        
        ProductScanView.frame=CGRectMake(200, 200, ProductscanBackView.frame.size.width-400, ProductscanBackView.frame.size.height-450);
   
        //ProductScanView.frame=CGRectMake(150, 300, ProductscanBackView.frame.size.width-300, ProductscanBackView.frame.size.height-750);
       
    CGFloat Productwidth=(ProductScanView.frame.size.width)/2;
    CGFloat Product=Productwidth/2;
 
    ScanTextlbl.frame=CGRectMake(10, 0,ProductScanView.frame.size.width-10, 100);
    ScanItemBtn.frame=CGRectMake(Product+20,105,Productwidth-30, 40);
    ProductScanField.frame=CGRectMake(Product-20,155,Productwidth+50, 40);
   
    
    SaveBarCodeBtn.frame=CGRectMake(Productwidth-90, 220, 80, 30);
    CancelBarCodeBtn.frame=CGRectMake(Productwidth+40, 220, 80, 30);
    
 //Recall invoice view
        
        RecallViewpopup.frame=CGRectMake(0, 0, 1024, 768);
    
        
       // RecallViewpopup.frame=CGRectMake(0, 0, 768, 1024);
    RecallListTable .frame= CGRectMake(20,50, RecallViewpopup.frame.size.width-40,RecallViewpopup.frame.size.height-100);
 

//Discount View
        
        DiscountPopupView.frame=CGRectMake(0, 0, 1024, 768);
   
        
       // DiscountPopupView.frame=CGRectMake(0, 0, 768, 1024);
   
        Discountview.frame=CGRectMake(200, 200, DiscountPopupView.frame.size.width-400, DiscountPopupView.frame.size.height-450);
   
        //Discountview.frame=CGRectMake(150, 300, DiscountPopupView.frame.size.width-300, DiscountPopupView.frame.size.height-750);
        
    CGFloat Diswidth=(Discountview.frame.size.width)/2;
    CGFloat dis=Diswidth/2;
    
  
    DiscountTextlbl.frame=CGRectMake(dis-60, 25,Diswidth, 50);

    ChangeDiscountField.frame=CGRectMake(10, 95,Diswidth+50, 40);

    DisDropdownBtn.frame=CGRectMake(ChangeDiscountField.frame.size.width+20, 95,150, 40);

    DisTableview.frame = CGRectMake(ChangeDiscountField.frame.size.width+20, 135, 150, 80);
   
    DisCheckBtn.frame=CGRectMake(30,140,40, 40);

    OverAllDislbl.frame=CGRectMake(80, 140,Diswidth, 40);
    SaveDiscountBtn.frame=CGRectMake(Diswidth-90, 220, 80, 30);
    CancelDiscountBtn.frame=CGRectMake(Diswidth+40, 220, 80, 30);
    
        
        if (ItemboolVlaue)
        {
            
            int btncount=0;
            int h=0;
            int w=0;
            CGFloat itemw=itemsView.frame.size.width/2;
            for (int i=0; i<[ItemsArray count]; i++)
            {
                
                if (btncount==2)
                {
                    h=h+70;
                    w=0;
                    
                    btncount=0;
                }
                
                UIButton *mybtn=(UIButton *)[itemsView viewWithTag:i+100];
                mybtn.frame=CGRectMake(w,h,itemw-10,60);
                [itemsView addSubview:mybtn];
               // UILabel *myLabel=(UILabel *)[mybtn viewWithTag:i+100];
                //titleLabel.frame=CGRectMake(0, 0, itemw-10, 60);
                //[mybtn addSubview:myLabel];
                
                btncount=btncount+1;
                w=itemw;
                
            }
           
        }
      
        
  //Check View
        
        checkPopUp.frame=CGRectMake(0, 0, 1024, 768);
   
        
      //  checkPopUp.frame=CGRectMake(0, 0, 768, 1024);
   
        checkPopUpPay.frame=CGRectMake(250, 150, checkPopUp.frame.size.width-500, checkPopUp.frame.size.height-530);
        
        // checkPopUpPay.contentSize=CGSizeMake(checkPopUp.frame.size.width-450, checkPopUp.frame.size.height+100);
    
       // checkPopUpPay.frame=CGRectMake(150, 200, checkPopUp.frame.size.width-300, checkPopUp.frame.size.height-800);
        
    CGFloat vwidth=checkPopUpPay.frame.size.width/2;

    checkNumLbl.frame=CGRectMake(vwidth-100, 20,300,40);
    checkNumTxt.frame=CGRectMake(vwidth-160,70,vwidth+100,40);
    
    checkNumBtn.frame=CGRectMake(vwidth-30, 150, 80, 40);
    
  //Modifier View
        modifierPopupView.frame=CGRectMake(0, 0, 1024, 768);
   
        //modifierPopupView.frame=CGRectMake(0, 0, 768, 1024);
   
        modifieView.frame=CGRectMake(225, 50, modifierPopupView.frame.size.width-450, modifierPopupView.frame.size.height-100);
        
   
        //modifieView.frame=CGRectMake(150, 200, modifierPopupView.frame.size.width-300, modifierPopupView.frame.size.height-400);
        
        if (modifierBoolValue)
        {
            int btncount=0;
            int h=20;
            int w=5;
            CGFloat itemw=modifieView.frame.size.width/2;
            for (int i=0; i<[modifierItemsArray count]; i++)
            {
                
                if (btncount==2){
                    h=h+70;
                    w=5;
                    
                    btncount=0;
                }
                
                
                UIButton *mybtn=(UIButton *)[modifieView viewWithTag:i+100];
                mybtn.frame=CGRectMake(w,h,itemw-10,60);
                [modifieView addSubview:mybtn];
                
                btncount=btncount+1;
                w=itemw;
                
            }
        }
    }
    else
    {
        CGFloat width,height;
        height=1004;
        width=768;
       // // //NSLog(@" %f,%f",width,height);
        
        
        backgroundcolorview.frame=CGRectMake(0,y,width,height-100);
        navBar.frame=CGRectMake(0, 0,width , 50.0);
        [logoBtn setFrame:CGRectMake(60,0,250,50)];
        
        
        sationLbl.frame=CGRectMake(navBar.frame.size.width-280, 5,100, 40);
        EmpIdlbl.frame=CGRectMake(navBar.frame.size.width-193, 5,150, 40);
        Timelbl.frame=CGRectMake(navBar.frame.size.width-62, 6,80, 40);
        
        
        //sidemenu.frame=CGRectMake(0, 1,170 ,height-150);
       // sidemenu.hidden=YES;
       [categorybutton setFrame:CGRectMake(0.0,p,170,40)];
      mainview.frame=CGRectMake(10,50,width-20,height-160);
        [menubutton setFrame:CGRectMake(0,0,50,50)];
        
        maintoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
        //downtoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
        
        logoimageview.frame=CGRectMake(50, (backgroundcolorview.frame.size.height)+5+y,(height-(backgroundcolorview.frame.size.height)-30), (height-(backgroundcolorview.frame.size.height)-30));
        
        [helpiconButton setFrame:CGRectMake(width-180,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
        
        [logouticonButton setFrame:CGRectMake(width-100,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
        Modelbl.frame=CGRectMake(20,400,60, 30);
        
        Myswitch.frame=CGRectMake(Modelbl.frame.size.width+20,400,100,40);
        
//home View
        
        HomebackView.frame=CGRectMake(0, 5,mainview.frame.size.width, mainview.frame.size.height-10);
        
        
        CGFloat homewidth=(HomebackView.frame.size.width/2);
        CGFloat btnw=homewidth/2;
        
        ProductscanBtn.frame=CGRectMake(0,5,btnw,40);
        ProductscanField.frame=CGRectMake(0,5,btnw,40);
        
        
       // ProductscanField.frame=CGRectMake(0,52,btnw-50, 40);
        
        Quantitybtn.frame=CGRectMake(ProductscanBtn.frame.size.width+10,5,btnw-100, 40);
        
        QantyField.frame=CGRectMake(ProductscanBtn.frame.size.width+5,5,btnw-140,40);
        
        QtyGobtn.frame=CGRectMake(ProductscanBtn.frame.size.width+QantyField.frame.size.width+12,5,40, 40);
        
        SearchBtn.frame=CGRectMake(ProductscanBtn.frame.size.width+20+QantyField.frame.size.width+40,5,btnw-110, 40);
        
        tablestripview.frame=CGRectMake(0, 60,homewidth,30);
        
        CGFloat sw=tablestripview.frame.size.width/5;
        
        snolbl.frame=CGRectMake(0,0, sw-30, 30);
        itemlbl.frame=CGRectMake(snolbl.frame.size.width,0, sw+50, 30);
        
        iteminfolbl.frame=CGRectMake(snolbl.frame.size.width+itemlbl.frame.size.width,0, sw+60, 30);
        
        qntylbl.frame=CGRectMake(snolbl.frame.size.width+itemlbl.frame.size.width+iteminfolbl.frame.size.width-40,0, sw-10, 30);
        
        pricelbl.frame=CGRectMake(snolbl.frame.size.width+itemlbl.frame.size.width+iteminfolbl.frame.size.width+qntylbl.frame.size.width-70,0, sw-20, 30);
        
        
        
        ProductslistTable.frame = CGRectMake(0, 90,homewidth,560);
        
        
        //ProductslistTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 130,homewidth,530) style:UITableViewStylePlain];
        
        CGFloat deW=ProductslistTable.frame.size.width/5;
        DeleteBtn.frame=CGRectMake(0,95+ProductslistTable.frame.size.height,deW-20, 40);
        
        DiscountBtn.frame=CGRectMake(DeleteBtn.frame.size.width+5,95+ProductslistTable.frame.size.height,deW-10, 40);
        
        QuantyChangeBtn.frame=CGRectMake(DeleteBtn.frame.size.width+5+DiscountBtn.frame.size.width+10,95+ProductslistTable.frame.size.height,deW+60, 40);
        
        
        PriceChangeBtn.frame=CGRectMake(DeleteBtn.frame.size.width+5+QuantyChangeBtn.frame.size.width+10+DiscountBtn.frame.size.width+10,95+ProductslistTable.frame.size.height,deW+20, 40);
        
        
        
        custBackview.frame=CGRectMake(0, 140+ProductslistTable.frame.size.height,homewidth,HomebackView.frame.size.height-(140+ProductslistTable.frame.size.height));
        
        
        //CGFloat homewidth=(tablestripview.frame.size.width/2);
        CGFloat Cw=custBackview.frame.size.width/4;
        CGFloat CH=custBackview.frame.size.height/2;
        
        AddBtn.frame=CGRectMake(0,140+ProductslistTable.frame.size.height,Cw-20, CH);
        
        FindBtn.frame=CGRectMake(0,140+ProductslistTable.frame.size.height+CH,Cw-20, CH);
        
        CustomerBtn.frame=CGRectMake(AddBtn.frame.size.width,140+ProductslistTable.frame.size.height+2,Cw, 40);
        CustomerinflBtn.frame=CGRectMake(AddBtn.frame.size.width+CustomerBtn.frame.size.width,140+ProductslistTable.frame.size.height+2,Cw+20, 40);
        
        Customernamelbl.frame=CGRectMake(FindBtn.frame.size.width,140+ProductslistTable.frame.size.height+2+CustomerBtn.frame.size.height+5,Cw+Cw+100, 30);
        
        CustomerNolbl.frame=CGRectMake(FindBtn.frame.size.width,140+ProductslistTable.frame.size.height+2+CustomerBtn.frame.size.height+Customernamelbl.frame.size.height+10,Cw+Cw+100, 30);
        
        SubtotalView.frame=CGRectMake(homewidth+10,0,homewidth-10,100);
        
        
        //CGFloat homewidth=(tablestripview.frame.size.width/2);
        CGFloat subW=SubtotalView.frame.size.width/2;
        
        
        Subtlbl.frame=CGRectMake(5,5,subW,30);
        
        SubTDisplaylbl.frame=CGRectMake(subW+80,0,subW,30);
        Taxlbl.frame=CGRectMake(5,60,subW,30);
        taxDlbl.frame=CGRectMake(subW+80,60,subW,30);
        
        blackstripview.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height,homewidth-10,2);
        GrandtotalView.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height+2,homewidth-10,40);
        
        CGFloat GW=GrandtotalView.frame.size.width/2;
        
        GrandTlbl.frame=CGRectMake(5,5,GW,30);
        
        GTotalDlbl.frame=CGRectMake(subW+80,5,GW,30);
        
        CGFloat Vwidth=homewidth/2;
        
        PayBtn.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height+45,Vwidth-10, 50);
        retraiveOnHoldBtn.frame=CGRectMake(homewidth+10+PayBtn.frame.size.width+10,SubtotalView.frame.size.height+45,Vwidth-10, 50);
        PrintLastInvcBtn.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height+100,Vwidth-10, 40);
        RecallBtn.frame=CGRectMake(homewidth+20+PrintLastInvcBtn.frame.size.width,SubtotalView.frame.size.height+100,Vwidth-10, 40);
        
        VoidInVoiceBtn.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height+145,Vwidth-10, 40);
        
        SplitInvoiceBtn.frame=CGRectMake(homewidth+20+VoidInVoiceBtn.frame.size.width,SubtotalView.frame.size.height+145,Vwidth-10, 40);
        
        
        CGFloat Cashwidth=homewidth/3;
        CheckBtn.frame=CGRectMake(homewidth+10,SubtotalView.frame.size.height+190,Cashwidth-10, 40);
        
        CashBtn.frame=CGRectMake(homewidth+20+CheckBtn.frame.size.width,SubtotalView.frame.size.height+190,Cashwidth-10, 40);
        
        CreditBtn.frame=CGRectMake(homewidth+20+CheckBtn.frame.size.width+CashBtn.frame.size.width+10,SubtotalView.frame.size.height+190,Cashwidth-10, 40);
        
        DepartmentsTable.frame = CGRectMake(homewidth+10, SubtotalView.frame.size.height+235,156,HomebackView.frame.size.height-(SubtotalView.frame.size.height+240));
        
        
        CGFloat homewidth3=HomebackView.frame.size.width/2;
       itemsView.frame =CGRectMake(homewidth3+10+DepartmentsTable.frame.size.width+5,SubtotalView.frame.size.height+235,(homewidth3-10-156),HomebackView.frame.size.height-(SubtotalView.frame.size.height+240));
        
    itemsView.contentSize=CGSizeMake((homewidth3-10-156), 60*[ItemsArray count]);
        
        
//tableview data view
    
     namelbl.frame=CGRectMake(0, 0, 30, 100);
      taxlbl.frame=CGRectMake(40,0,100,100);
       stock.frame=CGRectMake(140,0,120,100);
       Deslbl.frame=CGRectMake(270,0,30,100);
        Vendorlbl.frame=CGRectMake(300,0,40,100);
        
        [DeleteItemBtn setFrame:CGRectMake(340, 10, 25, 25)];
     
        
        
//Search Button  view
        
       // SearchViewpopup.frame=CGRectMake(0, 0, 1024, 768);
        SearchViewpopup.frame=CGRectMake(0, 0, 768, 1024);
        
        SearchView.frame=CGRectMake(20, 40, SearchViewpopup.frame.size.width-40, SearchViewpopup.frame.size.height-80);
        SearchView.contentSize=CGSizeMake(SearchViewpopup.frame.size.width-40, SearchViewpopup.frame.size.height+300);
        
        
        SearchlistTable.frame = CGRectMake(0,0, SearchView.frame.size.width,SearchView.frame.size.height-100);
        
        
        CGFloat SearchW=(SearchView.frame.size.width-20)/7;
        Catlbl.frame=CGRectMake(10,SearchlistTable.frame.size.height+25,SearchW-15,40);
        
        
        CatBtn.frame=CGRectMake(Catlbl.frame.size.width+10,SearchlistTable.frame.size.height+25,SearchW+15,40);
        
        Deptlbl.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+5,SearchlistTable.frame.size.height+25,SearchW+15, 40);
        
        DeptBtn.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+5,SearchlistTable.frame.size.height+25,SearchW+15, 40);
        
        SearchField.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+DeptBtn.frame.size.width+15,SearchlistTable.frame.size.height+25,SearchW+15, 40);
        
        
        ItemsDataTable.frame = CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+DeptBtn.frame.size.width+15,SearchlistTable.frame.size.height+25+40,SearchW+15, 100) ;
        
        
        Gobtn.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+DeptBtn.frame.size.width+SearchField.frame.size.width+20,SearchlistTable.frame.size.height+25,40, 40);
        
        
        CancelItemBtn.frame=CGRectMake(Catlbl.frame.size.width+10+CatBtn.frame.size.width+Deptlbl.frame.size.width+DeptBtn.frame.size.width+SearchField.frame.size.width+Gobtn.frame.size.width+25,SearchlistTable.frame.size.height+25,SearchW, 40);
      
//Category View
        
        //Pcategorypopup.frame=CGRectMake(0, 0, 1024, 768);
        Pcategorypopup.frame=CGRectMake(0, 0, 768, 1024);
        
        PCategorysTable.frame=CGRectMake(100,200 ,Pcategorypopup.frame.size.width-200, Pcategorypopup.frame.size.height-400);
//Department
        
        //Pdeaprtmentpopup.frame=CGRectMake(0, 0, 1024, 768);
        Pdeaprtmentpopup.frame=CGRectMake(0, 0, 768, 1024);
        PdepartmentsTable.frame=CGRectMake(100,200 ,Pdeaprtmentpopup.frame.size.width-200, Pdeaprtmentpopup.frame.size.height-400);
      
//Search data table view
        
          Snolbl.frame=CGRectMake(0, 0, 50, 40);
        itemnolbl.frame=CGRectMake(50, 0, 100, 60);
        
        Itemnamelbl.frame=CGRectMake(150, 0, 150, 60);
        
        Ppricelbl.frame=CGRectMake(300, 0, 100, 60);
      
        Instock.frame=CGRectMake(400, 0, 100, 60);
        
        Pdeslbl.frame=CGRectMake(500, 0, 100, 60);
        vendornolbl.frame=CGRectMake(590, 0, 150, 60);
        
        
//Change Quantity View
        
        //QuantityPopupView.frame=CGRectMake(0, 0, 1024, 768);
        
        QuantityPopupView.frame=CGRectMake(0, 0, 768, 1024);
        
        
        //Quantityview.frame=CGRectMake(200, 200, QuantityPopupView.frame.size.width-400, QuantityPopupView.frame.size.height-450);
        
         Quantityview.frame=CGRectMake(150, 300, QuantityPopupView.frame.size.width-300, QuantityPopupView.frame.size.height-750);
        
        
        
        CGFloat instwidth=(Quantityview.frame.size.width)/2;
        CGFloat inst=instwidth/2;
        
        QTextlbl.frame=CGRectMake(10, 25,Quantityview.frame.size.width-20, 50);
        
        ChangeQuantityField.frame=CGRectMake(20, 95,instwidth+50, 40);
        
        SaveQtyBtn.frame=CGRectMake(ChangeQuantityField.frame.size.width+40, 105, 80, 30);
        
        PrintatDeptlbl.frame=CGRectMake(inst-60,160,instwidth+20, 50);
        PrintDeptSwitch.frame=CGRectMake(PrintatDeptlbl.frame.size.width+60,172,100,40);
        Swicthtextlbl.frame=CGRectMake(PrintatDeptlbl.frame.size.width+60,210,100,40);
        
//Change Price View
        
       // PricePopupView.frame=CGRectMake(0, 0, 1024, 768);
        
        PricePopupView.frame=CGRectMake(0, 0, 768, 1024);
       // Priceview.frame=CGRectMake(200, 200, PricePopupView.frame.size.width-400, PricePopupView.frame.size.height-450);
        
        Priceview.frame=CGRectMake(150, 300, PricePopupView.frame.size.width-300, PricePopupView.frame.size.height-750);
        
        CGFloat Pricewidth=(Priceview.frame.size.width)/2;
        CGFloat pricew=Pricewidth/2;
        
        
        PriceTextlbl.frame=CGRectMake(pricew-60, 25,Pricewidth, 50);
        
        ChangePriceField.frame=CGRectMake(pricew-20, 95,Pricewidth+50, 40);
        SavePriceBtn.frame=CGRectMake(Pricewidth-90, 180, 80, 30);
        CancelPriceBtn.frame=CGRectMake(Pricewidth+40, 180, 80, 30);
      
        
        
//Pay view
        
        //PaypopupView.frame=CGRectMake(0, 0, 1024, 768);
        
        
        PaypopupView.frame=CGRectMake(0, 0, 768, 1024);
        
        
        //PayView.frame=CGRectMake(225, 50, PaypopupView.frame.size.width-450, PaypopupView.frame.size.height-100);
        
        //PayView.contentSize=CGSizeMake(PaypopupView.frame.size.width-400, PaypopupView.frame.size.height+100);
        
         PayView.frame=CGRectMake(150, 200, PaypopupView.frame.size.width-300, PaypopupView.frame.size.height-400);
        
        
        CGFloat payw=PayView.frame.size.width/2;
        
        
        Amountlbl.frame=CGRectMake(20, 10,payw, 40);
        
        AmountField.frame=CGRectMake(20, 50,payw-30, 40);
        
        GivenAmountlbl.frame=CGRectMake(20, 100,payw, 40);
        GivenAmountField.frame=CGRectMake(20, 150,payw-30, 40);
        [DeleteGivenAmntBtn setFrame:CGRectMake(GivenAmountField.frame.size.width-30,8, 25, 25)];
        
        Paytypelbl.frame=CGRectMake(20, 200,payw, 40);
        
        
        CashDropDown.frame=CGRectMake(20,250,payw-20,40);
        
        CashlistTable .frame=CGRectMake(20,290,payw-20,100) ;
        
        SplitInvoiceTable.frame = CGRectMake(Amountlbl.frame.size.width, 60,payw-10, 180);
        
        SelectPrinterBtn.frame=CGRectMake(20,250,payw-20,40);
        
        PayPrinterDataTable .frame= CGRectMake(20,290,payw-20,100) ;
        
        SelectPrinterlabel.frame=CGRectMake(Amountlbl.frame.size.width+10, 200,payw, 40);
        
        
        PrinterSwitch.frame=CGRectMake(Amountlbl.frame.size.width-30+Amountlbl.frame.size.width/2,255,100,40);
        
        
        
        CGFloat cashw=PayView.frame.size.width/6;
        CGFloat Wd=12;
        for (int i=0; i<6; i++)
        {
            
            
            UIButton *mybtn=(UIButton *)[PayView viewWithTag:i+100];
            mybtn.frame=CGRectMake(Wd,450,cashw-10,40);
            [PayView addSubview:mybtn];
            
            Wd=Wd+cashw-5;
            
            
        }
      
        SavePayBtn.frame=CGRectMake(payw-100, 550, 80, 40);
        
        
        CancelPayBtn.frame=CGRectMake(SavePayBtn.frame.size.width+payw-60, 550, 80, 40);
        
        
//Printer View
        
       //PrinterpopupView.frame=CGRectMake(0, 0, 1024, 768);
        
        
         PrinterpopupView.frame=CGRectMake(0, 0, 768, 1024);
        
        //PrinterView.frame=CGRectMake(200, 200, PrinterpopupView.frame.size.width-400, PrinterpopupView.frame.size.height-400);
        
        PrinterView.frame=CGRectMake(150, 300, PrinterpopupView.frame.size.width-300, PrinterpopupView.frame.size.height-700);
        
        
        
        CGFloat instwidth2=(PrinterView.frame.size.width)/2;
        CGFloat inst2=instwidth2/2;
        
        textlbl.frame=CGRectMake(inst2, 5,instwidth2, 40);
        
        selectprinterlbl.frame=CGRectMake(inst2-60, 45,instwidth2, 40);
        
        
        SelectPrintBtn.frame=CGRectMake(inst2-20, 95,instwidth2+50, 40);
        
        PrinterDataTable.frame =CGRectMake(inst2-20, 135,instwidth2+50, 100);
        YesPrintBtn.frame=CGRectMake(instwidth2-90, 280, 80, 30);
        
        NoPrintBtn.frame=CGRectMake(instwidth2+40, 280, 80, 30);
        
        
//Customer View
        
       // CustomerViewpopup.frame=CGRectMake(0, 0, 1024, 768);
        
        
        CustomerViewpopup.frame=CGRectMake(0, 0, 768, 1024);
        
        
        CustomerView.frame=CGRectMake(20, 40, CustomerViewpopup.frame.size.width-40, CustomerViewpopup.frame.size.height-80);
        
        CustomerView.contentSize=CGSizeMake(CustomerViewpopup.frame.size.width-40, CustomerViewpopup.frame.size.height+300);
        
        
        
        CustomerlistTable .frame= CGRectMake(0,0, CustomerView.frame.size.width,CustomerView.frame.size.height-100);
        
        
        CustomerSearchField.frame=CGRectMake(20,CustomerlistTable.frame.size.height+25,250, 40);
        
        CustomerDataTable.frame= CGRectMake(20,CustomerlistTable.frame.size.height+25+40,250, 100);
        CustomerGobtn.frame=CGRectMake(CustomerSearchField.frame.size.width+30,CustomerlistTable.frame.size.height+25,40, 40);
        
        CustomerCancelBtn.frame=CGRectMake(CustomerSearchField.frame.size.width+30+CustomerGobtn.frame.size.width+10,CustomerlistTable.frame.size.height+25,100, 40);
        
//Fetch on data View
        
       // FetchOnHoldBackView.frame=CGRectMake(0, 0, 1024, 768);
        
        FetchOnHoldBackView.frame=CGRectMake(0, 0, 768, 1024);
        
        
        FetchOnHoldView.frame=CGRectMake(20,100, FetchOnHoldBackView.frame.size.width-40, FetchOnHoldBackView.frame.size.height-200);
        
        CGFloat Fwidth=(FetchOnHoldView.frame.size.width)/2;
        
        
        Fetchlbl.frame=CGRectMake(Fwidth-60, 25,Fwidth, 50);
        
        FecthOnHoldlistTable.frame = CGRectMake(0,100, FetchOnHoldView.frame.size.width,FetchOnHoldView.frame.size.height-100);
        
        
//Product printer view
        
        ProductPrinterPopUp.frame=CGRectMake(0, 0, 768, 1024);
        
        
        ProductPrinterView.frame=CGRectMake(20, 100, ProductPrinterPopUp.frame.size.width-40, ProductPrinterPopUp.frame.size.height-200);
        
        ProductPrinterView.contentSize=CGSizeMake(ProductPrinterPopUp.frame.size.width-40, ProductPrinterPopUp.frame.size.height+300);
        
        CGFloat changeProductfieldwidth=(ProductPrinterView.frame.size.width)/2;
        
        
        
        PrintTextlbl.frame=CGRectMake(changeProductfieldwidth-180, 10,changeProductfieldwidth, 30);
        
        ProductPrintertable .frame= CGRectMake(10,60, ProductPrinterView.frame.size.width-20,ProductPrinterView.frame.size.height-300);
        SavePrintBtn.frame=CGRectMake(changeProductfieldwidth-80,ProductPrinterView.frame.size.height-100 , 80, 30);
        
        CancelPrintBtn.frame=CGRectMake(changeProductfieldwidth+40, ProductPrinterView.frame.size.height-100 , 80, 30);

       
//Store data View
        
        //StoresPopupView.frame=CGRectMake(0, 0, 1024, 768);
        
        
       StoresPopupView.frame=CGRectMake(0, 0, 768, 1024);
        
       // StoresView.frame=CGRectMake(100, 200, StoresPopupView.frame.size.width-200, StoresPopupView.frame.size.height-400);
        
      StoresView.frame=CGRectMake(50, 300, StoresPopupView.frame.size.width-100, StoresPopupView.frame.size.height-600);
        
        
        CGFloat widthfield4=(StoresView.frame.size.width)/4;
        
        SelectStorelbl.frame=CGRectMake(20,20,widthfield4,40);
        
        
        SelectStoreBtn.frame=CGRectMake(SelectStorelbl.frame.size.width+20, 20,widthfield4+10, 40);
        
        StoresListTable.frame = CGRectMake(SelectStorelbl.frame.size.width+20, 60,widthfield4+10, 100);
        ProceedStoreBtn.frame=CGRectMake(widthfield4+120,300,80,30);
    
        
//Product scan View
        
        //ProductscanBackView.frame=CGRectMake(0, 0, 1024, 768);
        
        ProductscanBackView.frame=CGRectMake(0, 0, 768, 1024);
        
       // ProductScanView.frame=CGRectMake(200, 200, ProductscanBackView.frame.size.width-400, ProductscanBackView.frame.size.height-450);
        
        ProductScanView.frame=CGRectMake(150, 300, ProductscanBackView.frame.size.width-300, ProductscanBackView.frame.size.height-750);
        
        CGFloat Productwidth=(ProductScanView.frame.size.width)/2;
        CGFloat Product=Productwidth/2;
        
        ScanTextlbl.frame=CGRectMake(10, 0,ProductScanView.frame.size.width-10, 100);
        ScanItemBtn.frame=CGRectMake(Product+20,105,Productwidth-30, 40);
        ProductScanField.frame=CGRectMake(Product-20,155,Productwidth+50, 40);
        
        
        SaveBarCodeBtn.frame=CGRectMake(Productwidth-90, 220, 80, 30);
        CancelBarCodeBtn.frame=CGRectMake(Productwidth+40, 220, 80, 30);
        
 
//Recall invoice view
        
        RecallViewpopup.frame=CGRectMake(0, 0, 768, 1024);
        
        
        // RecallViewpopup.frame=CGRectMake(0, 0, 768, 1024);
        RecallListTable .frame= CGRectMake(20,50, RecallViewpopup.frame.size.width-40,RecallViewpopup.frame.size.height-100);
        
 
//Discount View
        
        //DiscountPopupView.frame=CGRectMake(0, 0, 1024, 768);
        
        
      DiscountPopupView.frame=CGRectMake(0, 0, 768, 1024);
        
        //Discountview.frame=CGRectMake(200, 200, DiscountPopupView.frame.size.width-400, DiscountPopupView.frame.size.height-450);
        
        Discountview.frame=CGRectMake(150, 300, DiscountPopupView.frame.size.width-300, DiscountPopupView.frame.size.height-750);
        
        CGFloat Diswidth=(Discountview.frame.size.width)/2;
        CGFloat dis=Diswidth/2;
        
        
        DiscountTextlbl.frame=CGRectMake(dis-60, 25,Diswidth, 50);
        
        ChangeDiscountField.frame=CGRectMake(10, 95,Diswidth+50, 40);
        
        DisDropdownBtn.frame=CGRectMake(ChangeDiscountField.frame.size.width+20, 95,150, 40);
        
        DisTableview.frame = CGRectMake(ChangeDiscountField.frame.size.width+20, 135, 150, 80);
        
        DisCheckBtn.frame=CGRectMake(30,140,40, 40);
        
        OverAllDislbl.frame=CGRectMake(80, 140,Diswidth, 40);
        SaveDiscountBtn.frame=CGRectMake(Diswidth-90, 220, 80, 30);
        CancelDiscountBtn.frame=CGRectMake(Diswidth+40, 220, 80, 30);
      
        
        if (ItemboolVlaue)
        {
            
            int btncount=0;
            int h=0;
            int w=0;
            CGFloat itemw=itemsView.frame.size.width/2;
            for (int i=0; i<[ItemsArray count]; i++)
            {
                
                if (btncount==2)
                {
                    h=h+70;
                    w=0;
                    
                    btncount=0;
                }
                
                UIButton *mybtn=(UIButton *)[itemsView viewWithTag:i+100];
                mybtn.frame=CGRectMake(w,h,itemw-10,60);
                [itemsView addSubview:mybtn];
                 // titleLabel.frame=CGRectMake(0, 0, itemw-10, 60);
              //  UILabel *myLabel=(UILabel *)[mybtn viewWithTag:i+100];
                //myLabel.frame=CGRectMake(0, 0, itemw-10, 60);
               // [mybtn addSubview:myLabel];
                btncount=btncount+1;
                w=itemw;
               
                
            }
            
            
        }
        
        
//Check View
        
       // checkPopUp.frame=CGRectMake(0, 0, 1024, 768);
        
        
    checkPopUp.frame=CGRectMake(0, 0, 768, 1024);
        
        //checkPopUpPay.frame=CGRectMake(250, 150, checkPopUp.frame.size.width-500, checkPopUp.frame.size.height-530);
        
        // checkPopUpPay.contentSize=CGSizeMake(checkPopUp.frame.size.width-450, checkPopUp.frame.size.height+100);
        
    checkPopUpPay.frame=CGRectMake(150, 200, checkPopUp.frame.size.width-300, checkPopUp.frame.size.height-800);
        
        CGFloat vwidth=checkPopUpPay.frame.size.width/2;
        
        checkNumLbl.frame=CGRectMake(vwidth-100, 20,300,40);
        checkNumTxt.frame=CGRectMake(vwidth-160,70,vwidth+100,40);
        
        checkNumBtn.frame=CGRectMake(vwidth-30, 150, 80, 40);
        
//Modifier View
       // modifierPopupView.frame=CGRectMake(0, 0, 1024, 768);
        
        modifierPopupView.frame=CGRectMake(0, 0, 768, 1024);
        
        //modifieView.frame=CGRectMake(225, 50, modifierPopupView.frame.size.width-450, modifierPopupView.frame.size.height-100);
        
        
        modifieView.frame=CGRectMake(150, 200, modifierPopupView.frame.size.width-300, modifierPopupView.frame.size.height-400);
        
        
        if (modifierBoolValue)
        {
            int btncount=0;
            int h=20;
            int w=5;
            CGFloat itemw=modifieView.frame.size.width/2;
            for (int i=0; i<[modifierItemsArray count]; i++)
            {
                
                if (btncount==2){
                    h=h+70;
                    w=5;
                    
                    btncount=0;
                }

                
                UIButton *mybtn=(UIButton *)[modifieView viewWithTag:i+100];
                mybtn.frame=CGRectMake(w,h,itemw-10,60);
                [modifieView addSubview:mybtn];
             
                btncount=btncount+1;
                w=itemw;
                
            }
        }
       
    }
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [CustomerNosArray removeAllObjects],[CuFirstnamesArray removeAllObjects], [CuLastnamesArray removeAllObjects],[CuSnosArray removeAllObjects];
    
    CustomerNosArray=nil;
    CuFirstnamesArray=nil;
    CuLastnamesArray=nil;
    CuSnosArray=nil;
    
    [InVoiceIdsArray removeAllObjects],[TotalAmountsArray removeAllObjects],[paymentTypesArray removeAllObjects],[HoldIdsArray removeAllObjects],[RsonsArray removeAllObjects];
    InVoiceIdsArray=nil;
    TotalAmountsArray=nil;
    paymentTypesArray=nil;
    HoldIdsArray=nil;
    TimesArray=nil;
    RsonsArray=nil;
    
    [PrinttextView removeFromSuperview];
    //  [self payViewRemovingMethod];
    //[PaypopupView removeFromSuperview];
    NSArray *ProductPrinterPopUpArray = ProductPrinterPopUp.subviews;
    for (int i = 0; i<[ProductPrinterPopUpArray count]; i++) {
        UIView *vi =[ProductPrinterPopUpArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *ProductPrinterViewArray = ProductPrinterView.subviews;
    for (int i = 0; i<[ProductPrinterViewArray count]; i++) {
        UIView *vi =[ProductPrinterViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [ProductPrinterView removeFromSuperview],[ProductPrinterPopUp removeFromSuperview];
   [MinitsPopup removeFromSuperview];
    NSArray *printerPopupArray = printerPopup.subviews;
    for (int i = 0; i<[printerPopupArray count]; i++) {
        UIView *vi =[printerPopupArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [printerPopup removeFromSuperview];
    [self qtyViewremoveMethod];
     [self releaseAllviewsmethod];
    NSArray *SplitInvoicepopUpArray = SplitInvoicepopUp.subviews;
    for (int i = 0; i<[SplitInvoicepopUpArray count]; i++) {
        UIView *vi =[SplitInvoicepopUpArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *SplitInvoiceViewArray = SplitInvoiceView.subviews;
    for (int i = 0; i<[SplitInvoiceViewArray count]; i++) {
        UIView *vi =[SplitInvoiceViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [SplitInvoiceView removeFromSuperview];
    [SplitInvoicepopUp removeFromSuperview];
    [SplittablePopUpView removeFromSuperview];
    [StoresPopupView removeFromSuperview];
    
    for (UILabel *lab in [checkPopUpPay subviews]) {
        [lab removeFromSuperview];
    }
    
    for (UITextField * tf in [checkPopUpPay subviews]) {
        [tf removeFromSuperview];
    }
    
    for (UIButton *but in [checkPopUpPay subviews]) {
        [but removeFromSuperview];
    }
    for (UIView *view in [checkPopUp subviews]) {
        [view removeFromSuperview];
    }

    [checkPopUp removeFromSuperview];
    
   
    NSArray *PdeaprtmentpopupArray = Pdeaprtmentpopup.subviews;
    for (int i = 0; i<[PdeaprtmentpopupArray count]; i++) {
        UIView *vi =[PdeaprtmentpopupArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [Pdeaprtmentpopup removeFromSuperview];
}

-(void)menuclicked
{
    if (menuslected == false)
    {
        
      //  // //NSLog(@"called");
       // // //NSLog(@"%d",menuslected);
        menuslected=YES;
        logoBtn.hidden=YES;
      
       // [UIView beginAnimations:nil context:NULL];
       // [UIView setAnimationDuration:1.0f];
        sidemenu.transform = CGAffineTransformMakeTranslation(0,0);
        //[SideMenuView setBackgroundColor:[UIColor whiteColor]];
        //sidemenu.hidden=NO;
      //  [UIView commitAnimations];
       [backgroundcolorview addSubview:sidemenu];
      //
      //  [UIView beginAnimations:nil context:NULL];
     //   [UIView setAnimationDuration:0.9f];
        menubutton.transform = CGAffineTransformMakeTranslation(180,0);
        
        menubutton.transform = CGAffineTransformRotate( menubutton.transform, - M_PI);
     //   [UIView commitAnimations];
       
        
    }else
    {
        
        menuslected=NO;
         logoBtn.hidden=NO;
        
       // [UIView beginAnimations:nil context:NULL];
       // [UIView setAnimationDuration:1.0f];
        sidemenu.transform = CGAffineTransformMakeTranslation(-250,0);
      
       // [UIView commitAnimations];
      
        
        
        
      //  [UIView beginAnimations:nil context:NULL];
      //  [UIView setAnimationDuration:1.0f];
        menubutton.transform = CGAffineTransformMakeTranslation(0,0);
        
        
      //  [UIView commitAnimations];
       // [UIView beginAnimations:nil context:NULL];
       // [UIView setAnimationDuration:1.0f];
        
    }

}

/*-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    
    logoBtn.hidden=NO;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.8f];
    mainview.transform = CGAffineTransformMakeTranslation(0,0);
    
    
    [UIView commitAnimations];
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.8f];
    sidemenu.transform = CGAffineTransformMakeTranslation(-250,0);
    //[SideMenuView setBackgroundColor:[UIColor whiteColor]];
    
    [UIView commitAnimations];
    [UIView commitAnimations];
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.0f];
    menubutton.transform = CGAffineTransformMakeTranslation(0,0);
    
    
    [UIView commitAnimations];
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.0f];
    menuslected=NO;
}*/
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    
  if (textField==ProductscanField)
  {
        [retraiveOnHoldBtn setTitle:@"Save on Hold" forState:UIControlStateNormal];
        
      NSString *querySQL = [NSString stringWithFormat:@"SELECT inventary_department,inventory_item_no,inventary_item_name,inventary_second_description,inventary_avg_cost,inventary_price_tax,inventary_price_change,inventary_in_stock,inventary_quantity,inventary_taxone,inventary_vendor FROM inventorytable"];
      NSMutableArray *productDataArray=[[NSMutableArray alloc]init];
      [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:productDataArray];
      NSMutableArray *myitemnumbersArray;
      if (!myitemnumbersArray)
        myitemnumbersArray=[[NSMutableArray alloc]init];
        
        for (NSDictionary *myDict in productDataArray)
        {
            [myitemnumbersArray addObject:[myDict objectForKey:@"inventory_item_no"]];
        }
        
        
        NSUInteger objIdx = [myitemnumbersArray containsObject:ProductscanField.text];
        //// //NSLog(@"%lu",(unsigned long)objIdx);
        if(objIdx == 0)
        {
            UIAlertView *itemalert=[[UIAlertView alloc]initWithTitle:@"Wrong" message:@"Wrong barcode" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
            [itemalert show];
        }
        else
        {
            for (NSDictionary *myDict in productDataArray)
            {
                NSString *itemstr=[myDict objectForKey:@"inventory_item_no"];
                if ([itemstr isEqualToString:ProductscanField.text])
                {
                    NSString *itemno=[myDict objectForKey:@"inventory_item_no"];
                    //NSString *Qty=[myDict objectForKey:@"inventary_quantity"];
                    NSString *price=[myDict objectForKey:@"inventary_price_change"];
                    
                    
                    
                    if ([ItemNosArray count]>0)
                    {
                        NSUInteger objIdx = [ItemNosArray containsObject:itemno];
                        //// //NSLog(@"%lu",(unsigned long)objIdx);
                        if(objIdx == 0)
                        {
                            [ItemNosArray addObject:[myDict objectForKey:@"inventory_item_no"]];
                            [ItemNamesArray addObject:[myDict objectForKey:@"inventary_item_name"]];
                            
                            
                            [TaxesArray addObject:[myDict objectForKey:@"inventory_total_tax"]];
                            [AvegCostsArray addObject:[myDict objectForKey:@"inventary_avg_cost"]];
                            [DiscountsArray addObject:@"0"];
                            
                            [ItemVendorArray addObject:[myDict objectForKey:@"inventary_vendor"]];
                            [ItemDeptsArray addObject:[myDict objectForKey:@"inventary_department"]];
                            [ItemDesArray addObject:[myDict objectForKey:@"inventary_second_description"]];
                            [SnosArray addObject:[NSString stringWithFormat:@"%d",[ItemNamesArray count]]];
                            
                            if ([QantyField .text length]>0)
                            {
                                [QntysArray addObject:QantyField.text];
                                
                                Pricevalue=[QantyField.text doubleValue]*[price doubleValue];
                                [pricesArray addObject:[NSString stringWithFormat:@"%0.02f",Pricevalue]];
                            }
                            else
                            {
                                [QntysArray addObject:[myDict objectForKey:@"inventary_quantity"]];
                                [pricesArray addObject:[myDict objectForKey:@"inventary_price_change"]];
                            }
                        }
                        else
                        {
                            NSInteger qindex=[ItemNosArray indexOfObject:itemno];
                            //NSString *anotherqty=[QntysArray objectAtIndex:qindex];
                            // NSString *anotherprice=[pricesArray objectAtIndex:qindex];
                            
                            
                            
                            quantity=[QantyField.text intValue];
                            Pricevalue=Pricevalue=[QantyField.text doubleValue]*[price doubleValue];
                            
                            
                            [QntysArray removeObjectAtIndex:qindex];
                            [pricesArray removeObjectAtIndex:qindex];
                            [QntysArray insertObject:[NSString stringWithFormat:@"%d",quantity] atIndex:qindex];
                            [pricesArray insertObject:[NSString stringWithFormat:@"%0.02f",Pricevalue] atIndex:qindex];
                            
                            //[SnosArray addObject:[NSString stringWithFormat:@"%d",[ItemNamesArray count]]];
                        }
                    }
                    else
                    {
                        
                        [ItemNosArray addObject:[myDict objectForKey:@"inventory_item_no"]];
                        [ItemNamesArray addObject:[myDict objectForKey:@"inventary_item_name"]];
                        [TaxesArray addObject:[myDict objectForKey:@"inventory_total_tax"]];
                        [AvegCostsArray addObject:[myDict objectForKey:@"inventary_avg_cost"]];
                        [DiscountsArray addObject:@"0"];
                        
                        [ItemVendorArray addObject:[myDict objectForKey:@"inventary_vendor"]];
                        [ItemDeptsArray addObject:[myDict objectForKey:@"inventary_department"]];
                        [ItemDesArray addObject:[myDict objectForKey:@"inventary_second_description"]];
                        [SnosArray addObject:[NSString stringWithFormat:@"%d",[ItemNosArray count]]];
                        
                        if ([QantyField .text length]>0)
                        {
                            [QntysArray addObject:QantyField.text];
                            
                         Pricevalue=[QantyField.text doubleValue]*[price doubleValue];
                         [pricesArray addObject:[NSString stringWithFormat:@"%0.02f",Pricevalue]];
                            
                            
                        }
                        else
                        {
                            [QntysArray addObject:[myDict objectForKey:@"inventary_quantity"]];
                            [pricesArray addObject:[myDict objectForKey:@"inventary_price_change"]];
                        }
                        
                    }
                    
                    
                   // // //NSLog(@"%@",TaxesArray);
                    
                    itemno=nil,price=nil;
                }
                itemstr=nil;
            }
            //// //NSLog(@"%@",ItemNamesArray);
            
            [ProductslistTable reloadData];
            [self GetTotalAmountMethod];
            
            ProductscanField.text=@"";

    }
  }
    [textField resignFirstResponder];
    
    return YES;
}
-(void) releaseAllviewsmethod
{
    NSArray *RecallViewpopupArray = RecallViewpopup.subviews;
    for (int i = 0; i<[RecallViewpopupArray count]; i++) {
        UIView *vi =[RecallViewpopupArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [RecallViewpopup removeFromSuperview];
    RecallViewpopup=nil;
    
    NSArray *FetchOnHoldBackViewArray = FetchOnHoldBackView.subviews;
    for (int i = 0; i<[FetchOnHoldBackViewArray count]; i++) {
        UIView *vi =[FetchOnHoldBackViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *FetchOnHoldViewArray = FetchOnHoldView.subviews;
    for (int i = 0; i<[FetchOnHoldViewArray count]; i++) {
        UIView *vi =[FetchOnHoldViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [FetchOnHoldView removeFromSuperview],[FetchOnHoldBackView removeFromSuperview];
    FetchOnHoldBackView=nil,FetchOnHoldView=nil;
    
    NSArray *QuantityPopupViewArray = QuantityPopupView.subviews;
    for (int i = 0; i<[QuantityPopupViewArray count]; i++) {
        UIView *vi =[QuantityPopupViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *QuantityviewArray = Quantityview.subviews;
    for (int i = 0; i<[QuantityviewArray count]; i++) {
        UIView *vi =[QuantityviewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [Quantityview removeFromSuperview],[QuantityPopupView removeFromSuperview];
    QuantityPopupView=nil,Quantityview=nil;
    
}
-(void)helpiconclicked
{
   
   
}
-(void)logoutButtonClicked
{
       [serverSyncClassObject LogoutMethod];
    
    NSString *updateSQL =@"UPDATE miscellaneous SET userType=?,sessionId=?,userID=?";
    NSMutableArray *misUpdatearray=[[NSMutableArray alloc]initWithObjects:@"",@"",@"", nil];
    [[DataBaseManager dataBaseManager] executeRecordsWithQuery:updateSQL withArguments:misUpdatearray];
    [self.navigationController popToRootViewControllerAnimated:YES];
    [self releaseViews];
    [generalDataObject   releasevariable];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
   
    return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
   
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
     [self GetPrint:&webView];
    [webView removeFromSuperview];
    [webView loadRequest:nil];
    webView=nil;
    

}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
   // // //NSLog(@"didFailLoadWithError called error is %@",[error userInfo]);
}

-(void)categotybuttonclicked:(UIButton *)sender
{
    NSArray *viewS = [self.navigationController viewControllers];
   //NSLog(@"nav views %@",viewS);

    NSInteger selectedrow=sender.tag;
    if(selectedrow == 5){
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  settings_permission] isEqualToString:@"yes"])
            {

                NSString *returnvalue;
                NSInteger selectedview;
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Settings class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                    settingsview=[[Settings alloc]initWithNibName:@"Settings" bundle:Nil];
                    [self.navigationController pushViewController:settingsview animated:NO];
                    [self releaseViews];
                }

            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }else{
           
            NSString *returnvalue;
             NSInteger selectedview;
          for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Settings class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
               
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
               [self releaseViews];
            }else
            {
                settingsview=[[Settings alloc]initWithNibName:@"Settings" bundle:Nil];
                [self.navigationController pushViewController:settingsview animated:NO];
                [self releaseViews];
            }
            
            
        }
   
    
    }else if(selectedrow == 1){
        if ([[generalDataObject  userType] isEqualToString:@"admin"])
        {
            NSString *returnvalue;
            NSInteger selectedview;
            Profile *profileview=[[Profile alloc]initWithNibName:@"Profile" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Profile class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
               
                [self.navigationController pushViewController:profileview animated:NO];
                [self releaseViews];
            }
        }else{
            UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
            [authalert show];
            authalert=nil;
        }
    }else if(selectedrow == 8){
        NSString *returnvalue;
        NSInteger selectedview;
        Stores *storesview=[[Stores alloc]initWithNibName:@"Stores" bundle:Nil];
        for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
        {
            if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Stores class]])
            {
                returnvalue=@"yes";
                selectedview=m;
                break;
            }
            
        }
        if([returnvalue isEqualToString:@"yes"])
        {
            [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
            [self releaseViews];
        }else
        {
            
            [self.navigationController pushViewController:storesview animated:NO];
            [self releaseViews];
        }

    }else if(selectedrow == 2){
        
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  inventory_permission] isEqualToString:@"yes"])
            {
                NSString *returnvalue;
                NSInteger selectedview;
                Inventory *inventoryview=[[Inventory alloc]initWithNibName:@"Inventory" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Inventory class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                    
                    [self.navigationController pushViewController:inventoryview animated:NO];
                    [self releaseViews];
                }

            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }
        else
        {
            NSString *returnvalue;
            NSInteger selectedview;
            Inventory *inventoryview=[[Inventory alloc]initWithNibName:@"Inventory" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Inventory class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:inventoryview animated:NO];
                [self releaseViews];
            }
        }
    }else if(selectedrow == 3){
        
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  customer_permission] isEqualToString:@"yes"])
            {
                NSString *returnvalue;
                NSInteger selectedview;
                Customers *customersview=[[Customers alloc]initWithNibName:@"Customers" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Customers class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                    
                    [self.navigationController pushViewController:customersview animated:NO];
                    [self releaseViews];
                }
                
            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }else{
            
            NSString *returnvalue;
            NSInteger selectedview;
            Customers *customersview=[[Customers alloc]initWithNibName:@"Customers" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Customers class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:customersview animated:NO];
                [self releaseViews];
            }
        }
        
    }else if(selectedrow == 4){
        if ([[generalDataObject  userType] isEqualToString:@"admin"])
        {
            NSString *returnvalue;
            NSInteger selectedview;
            Employees *employeesview=[[Employees alloc]initWithNibName:@"Employees" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Employees class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:employeesview animated:NO];
                [self releaseViews];
            }

        }
       else
       {
        UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
        
        [authalert show];
        }
    
    }else if(selectedrow == 6){
        
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  settings_permission] isEqualToString:@"yes"])
            {
                NSString *returnvalue;
                NSInteger selectedview;
                Reports *reportsview=[[Reports alloc]initWithNibName:@"Reports" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Reports class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                   [self releaseViews];
                }else
                {
                    
                    [self.navigationController pushViewController:reportsview animated:NO];
                    [self releaseViews];
                }

        }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }else{
            
            NSString *returnvalue;
            NSInteger selectedview;
            Reports *reportsview=[[Reports alloc]initWithNibName:@"Reports" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Reports class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:reportsview animated:NO];
                [self releaseViews];
            }
            
        }
        
    }else if(selectedrow == 7){
        NSString *returnvalue;
        NSInteger selectedview;
        Contacts *contactsview=[[Contacts alloc]initWithNibName:@"Contacts" bundle:Nil];
        for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
        {
            if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Contacts class]])
            {
                returnvalue=@"yes";
                selectedview=m;
                break;
            }
            
        }
        if([returnvalue isEqualToString:@"yes"])
        {
            [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
            [self releaseViews];
        }else
        {
            [self.navigationController pushViewController:contactsview animated:NO];
            [self releaseViews];
        }
        
    }

}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

{
    if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight||toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
        isLandScope=YES;
        
    }else
    {
        isLandScope=NO;
    }
    [self updateUI];
}


- (NSUInteger)supportedInterfaceOrientations // iOS 6 autorotation fix
{
    return UIInterfaceOrientationMaskAll;
}
-(void)releaseViews
{
    NSArray *mainArray = self.view.subviews;
    for (int i = 0; i<[mainArray count]; i++) {
        UIView *vi =[mainArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    ////NSLog(@"mainarray %@",mainArray);
    
    NSArray *sideArray = sidemenu.subviews;
    for (int i = 0; i<[sideArray count]; i++) {
        UIView *vi =[sideArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    
    NSArray *navBarArray = navBar.subviews;
    for (int i = 0; i<[navBarArray count]; i++) {
        UIView *vi =[navBarArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *HomebackArray = HomebackView.subviews;
    for (int i = 0; i<[HomebackArray count]; i++) {
        UIView *vi =[HomebackArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *tablestripviewArray = tablestripview.subviews;
    for (int i = 0; i<[tablestripviewArray count]; i++) {
        UIView *vi =[tablestripviewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *SubtotalViewArray = SubtotalView.subviews;
    for (int i = 0; i<[SubtotalViewArray count]; i++) {
        UIView *vi =[SubtotalViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *blackstripviewArray = blackstripview.subviews;
    for (int i = 0; i<[blackstripviewArray count]; i++) {
        UIView *vi =[blackstripviewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *GrandtotalViewArray = GrandtotalView.subviews;
    for (int i = 0; i<[GrandtotalViewArray count]; i++) {
        UIView *vi =[GrandtotalViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [sidemenu removeFromSuperview],[mainview removeFromSuperview],[backgroundcolorview removeFromSuperview],[HomebackView removeFromSuperview], [tablestripview removeFromSuperview],[SubtotalView removeFromSuperview],[blackstripview removeFromSuperview],[GrandtotalView removeFromSuperview];
    sidemenu=nil,mainview=nil,backgroundcolorview=nil;
    categorybutton=nil;
     downtoolBar=nil,maintoolBar=nil;
     logobackview=nil,logoimageview=nil;
 
    helpiconButton=nil,logouticonButton=nil,menubutton=nil;
  
    backButton3=nil,backButton2=nil,backButton=nil;
     navBar=nil;
    
    HomebackView=nil;
    ProductscanBtn=nil,Quantitybtn=nil,QtyGobtn=nil,DeleteBtn=nil,PriceChangeBtn=nil,QuantyChangeBtn=nil,DiscountBtn=nil,PayBtn=nil;
    ProductscanField=nil,QantyField=nil;
    VoidInVoiceBtn=nil,retraiveOnHoldBtn=nil,CashBtn=nil,CheckBtn=nil,CreditBtn=nil,SearchBtn=nil;
    ProductslistTable=nil;
    tablestripview=nil;
    snolbl=nil,itemlbl=nil,iteminfolbl=nil,qntylbl=nil,pricelbl=nil;
    
    custBackview=nil;
    AddBtn=nil,FindBtn=nil,CustomerBtn=nil,CustomerinflBtn=nil;
    
    
    SubtotalView=nil,blackstripview=nil,GrandtotalView=nil;
    
    Subtlbl=nil,SubTDisplaylbl=nil,Taxlbl=nil,taxDlbl=nil,GrandTlbl=nil,GTotalDlbl=nil;
    
    DepartmentsTable=nil;
    [departmentsArray removeAllObjects],[ItemsArray removeAllObjects],[ItemChecksArray removeAllObjects];
    departmentsArray=nil,ItemsArray=nil,ItemChecksArray=nil;
    
    ItemBtn=nil;
    itemsView=nil;
    
    [ItemNosArray removeAllObjects],[ItemnameArray removeAllObjects],[ItemNamesArray removeAllObjects],[QntysArray removeAllObjects],[pricesArray removeAllObjects],[productnosArray removeAllObjects],[SnosArray removeAllObjects],[TaxesArray removeAllObjects];
    ItemNosArray=nil,ItemNamesArray=nil,QntysArray=nil,pricesArray=nil,productnosArray=nil,SnosArray=nil,TaxesArray=nil;
    
    DeleteItemBtn=nil;
    namelbl=nil, taxlbl=nil,stock=nil,Deslbl=nil,Vendorlbl=nil;
    ItemsDeleteAlert=nil;
    
    //Search Data View
    NSArray *SearchViewpopupArray = SearchViewpopup.subviews;
    for (int i = 0; i<[SearchViewpopupArray count]; i++) {
        UIView *vi =[SearchViewpopupArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *SearchViewArray = SearchView.subviews;
    for (int i = 0; i<[SearchViewArray count]; i++) {
        UIView *vi =[SearchViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [SearchView removeFromSuperview],[SearchViewpopup removeFromSuperview];
    SearchViewpopup=nil;
    SearchView=nil;
    SearchlistTable=nil;
    Catlbl=nil,Deptlbl=nil;
    CatBtn=nil,DeptBtn=nil,Gobtn=nil,CancelItemBtn=nil;
    SearchField=nil;
    
    //product category view
    NSArray *PcategorypopupArray = Pcategorypopup.subviews;
    for (int i = 0; i<[PcategorypopupArray count]; i++) {
        UIView *vi =[PcategorypopupArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [Pcategorypopup removeFromSuperview];
    Pcategorypopup=nil;
    PCategorysTable=nil;
    //Product department view
    NSArray *PdeaprtmentpopupArray = Pdeaprtmentpopup.subviews;
    for (int i = 0; i<[PdeaprtmentpopupArray count]; i++) {
        UIView *vi =[PdeaprtmentpopupArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [Pdeaprtmentpopup removeFromSuperview];
    Pdeaprtmentpopup=nil;
    PdepartmentsTable=nil;
    ItemsDataTable=nil;
    [SearchDataArray removeAllObjects];
    [pastDataArray removeAllObjects];
   [DepartmentNamesArray removeAllObjects],[categorynamesArray removeAllObjects];
    
    [ItemNumbersArray removeAllObjects],[ItemnameArray removeAllObjects],[productDesArray removeAllObjects],[priceyouchargeArray removeAllObjects],[InstockArray removeAllObjects],[VendorpartNosArray removeAllObjects];
    SearchDataArray=nil;
    pastDataArray=nil;
    DepartmentNamesArray=nil,categorynamesArray=nil;
    
    ItemNumbersArray=nil,ItemnameArray=nil,productDesArray=nil,priceyouchargeArray=nil,InstockArray=nil,VendorpartNosArray=nil;
    
    itemnolbl=nil,Itemnamelbl=nil,Ppricelbl=nil,Instock=nil,Pdeslbl=nil,vendornolbl=nil,Snolbl=nil;
    
    
    SubTotalstr=nil,TaxValueStr=nil,GrandTotalstr=nil,TotalAvgStr=nil;
   
    // Change Quantity View
    NSArray *QuantityPopupViewArray = QuantityPopupView.subviews;
    for (int i = 0; i<[QuantityPopupViewArray count]; i++) {
        UIView *vi =[QuantityPopupViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *QuantityviewArray = Quantityview.subviews;
    for (int i = 0; i<[QuantityviewArray count]; i++) {
        UIView *vi =[QuantityviewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [Quantityview removeFromSuperview],[QuantityPopupView removeFromSuperview];
    QuantityPopupView=nil,Quantityview=nil;
    QTextlbl=nil;
    SaveQtyBtn=nil,CancelQtyBtn=nil;
    ChangeQuantityField=nil;
    
    // Change price View
    NSArray *PricePopupViewArray = PricePopupView.subviews;
    for (int i = 0; i<[PricePopupViewArray count]; i++) {
        UIView *vi =[PricePopupViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *PriceviewArray = Priceview.subviews;
    for (int i = 0; i<[PriceviewArray count]; i++) {
        UIView *vi =[PriceviewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [Priceview removeFromSuperview],[PricePopupView removeFromSuperview];
    PricePopupView=nil,Priceview=nil;
    PriceTextlbl=nil;
    SavePriceBtn=nil,CancelPriceBtn=nil;
    ChangePriceField=nil;
    // Change Discount View
    NSArray *DiscountPopupViewArray = DiscountPopupView.subviews;
    for (int i = 0; i<[DiscountPopupViewArray count]; i++) {
        UIView *vi =[DiscountPopupViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *DiscountviewArray = Discountview.subviews;
    for (int i = 0; i<[DiscountviewArray count]; i++) {
        UIView *vi =[DiscountviewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [Discountview removeFromSuperview],[DiscountPopupView removeFromSuperview];
    DiscountPopupView=nil,Discountview=nil;
    DiscountTextlbl=nil,OverAllDislbl=nil;
    SaveDiscountBtn=nil,CancelDiscountBtn=nil;
    ChangeDiscountField=nil;
    
    DisCheckBtn=nil,DisDropdownBtn=nil;
    DisTableview=nil;
    [DiscsArray removeAllObjects];
    DiscsArray=nil;
    //Pay View
   
    NSArray *PaypopupViewArray = PaypopupView.subviews;
    for (int i = 0; i<[PaypopupViewArray count]; i++) {
        UIView *vi =[PaypopupViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *PayViewArray = PayView.subviews;
    for (int i = 0; i<[PayViewArray count]; i++) {
        UIView *vi =[PayViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [Quantityview removeFromSuperview],[PaypopupView removeFromSuperview];
    PaypopupView=nil;
    PayView=nil;
    
    Amountlbl=nil,GivenAmountlbl=nil,Paytypelbl=nil,SelectPrinterlabel=nil,PrintertextLbl=nil;
    AmountField=nil,GivenAmountField=nil;
    CashDropDown=nil,AmountBtn=nil,CancelPayBtn=nil,SavePayBtn=nil,SelectPrinterBtn=nil;
    DeleteGivenAmntBtn=nil;
    CashlistTable=nil,PayPrinterDataTable=nil;
  
     paytypesArray=nil;
     PrinterSwitch=nil;
    [PrinterIpsArray removeAllObjects];
    PrinterIpsArray=nil;
    
    PrinterswitchValue=nil;
    [printcharArray removeAllObjects],[FontsArray removeAllObjects],[AlignsArray removeAllObjects],[languagesArray removeAllObjects],[WidthsArray removeAllObjects], [HeightsArray removeAllObjects],[boldsArray removeAllObjects],[UnderlinesArray removeAllObjects],[XpossArray removeAllObjects],[unitsArray removeAllObjects],[spacingsArray removeAllObjects],[printernamesArray removeAllObjects],[IpAddsArray removeAllObjects],[DBPrintertypesArray removeAllObjects];
    printcharArray=nil,FontsArray=nil,AlignsArray=nil,languagesArray=nil,WidthsArray=nil,HeightsArray=nil,boldsArray=nil,UnderlinesArray=nil,XpossArray=nil,unitsArray=nil,spacingsArray=nil,printernamesArray=nil,IpAddsArray=nil,DBPrintertypesArray=nil;
    
    PayPrinterName=nil,printChar=nil,font=nil,align=nil,language=nil,Pwidth=nil,Pheight=nil,Bold=nil,Underline=nil,xposition=nil,spacing=nil,Ipadd=nil,unit=nil,Dbprintertype=nil;
    
    
    //
    Changealert=nil;
      [DiscountsArray removeAllObjects],[AvegCostsArray removeAllObjects],[ItemDesArray removeAllObjects],[ItemVendorArray removeAllObjects],[ItemDeptsArray removeAllObjects];
    DiscountsArray=nil,AvegCostsArray=nil,ItemDesArray=nil,ItemVendorArray=nil,ItemDeptsArray=nil;
    
    paymentType=nil;
    HoldStatus=nil;
    
     InvoiceItemsConnection=nil,InvoiceTotalConnection=nil;
     InvoiceItemData=nil,InvoiceTotalData=nil;
    
    
    //Printer View
    NSArray *PrinterpopupViewArray = PrinterpopupView.subviews;
    for (int i = 0; i<[PrinterpopupViewArray count]; i++) {
        UIView *vi =[PrinterpopupViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *PrinterViewArray = PrinterView.subviews;
    for (int i = 0; i<[PrinterViewArray count]; i++) {
        UIView *vi =[PrinterViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [PrinterView removeFromSuperview],[PrinterpopupView removeFromSuperview];
    PrinterpopupView=nil,PrinterView=nil;
    textlbl=nil,selectprinterlbl=nil;
    SelectPrintBtn=nil,YesPrintBtn=nil,NoPrintBtn=nil;
    PrinterDataTable=nil;
    PrintersArray=nil;
    
     Myswitch=nil;
    Modelbl=nil;
    remainingamountstr=nil;
    
    
    //Customer View
    NSArray *CustomerViewpopupArray = CustomerViewpopup.subviews;
    for (int i = 0; i<[CustomerViewpopupArray count]; i++) {
        UIView *vi =[CustomerViewpopupArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *CustomerViewArray = CustomerView.subviews;
    for (int i = 0; i<[CustomerViewArray count]; i++) {
        UIView *vi =[CustomerViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [CustomerView removeFromSuperview],[CustomerViewpopup removeFromSuperview];
    CustomerViewpopup=nil;
    CustomerView=nil;
    CustomerlistTable=nil;
    CustomerGobtn=nil,CustomerCancelBtn=nil;
    CustomerSearchField=nil;
    CustomerDataTable=nil;
    
    [CustomerPastDataArray removeAllObjects],[CustomerDataArray removeAllObjects];
    CustomerPastDataArray=nil,CustomerDataArray=nil;
    [CustomerNosArray removeAllObjects],[CuFirstnamesArray removeAllObjects],[CuLastnamesArray removeAllObjects],[ShCompanynamesArray removeAllObjects],[ShPhonenumbersArray removeAllObjects],[CuSnosArray removeAllObjects];
    CustomerNosArray=nil,CuFirstnamesArray=nil,CuLastnamesArray=nil,ShCompanynamesArray=nil,ShPhonenumbersArray=nil,CuSnosArray=nil;
    
    CustomerNO=nil,CustomerName=nil,CusomerCompany=nil,CustomerPhoneNumber=nil;
    
    
    Customernamelbl=nil,CustomerNolbl=nil;
    
  
    
    //Fetch On Hold View
    
    NSArray *FetchOnHoldBackViewArray = FetchOnHoldBackView.subviews;
    for (int i = 0; i<[FetchOnHoldBackViewArray count]; i++) {
        UIView *vi =[FetchOnHoldBackViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *FetchOnHoldViewArray = FetchOnHoldView.subviews;
    for (int i = 0; i<[FetchOnHoldViewArray count]; i++) {
        UIView *vi =[FetchOnHoldViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [FetchOnHoldView removeFromSuperview],[FetchOnHoldBackView removeFromSuperview];
    FetchOnHoldBackView=nil,FetchOnHoldView=nil;
    
    FecthOnHoldlistTable=nil;
    Fetchlbl=nil;
    PrintatDeptlbl=nil,Swicthtextlbl=nil;
     PrintDeptSwitch=nil;
    HoldID=nil,invoiceID=nil;
    DeptSwitchValue=nil;
    [InVoiceIdsArray removeAllObjects],[TotalAmountsArray removeAllObjects],[StatusArray removeAllObjects],[HoldIdsArray removeAllObjects],[TimesArray removeAllObjects],[CustomersArray removeAllObjects],[EmployeesArray removeAllObjects];
    InVoiceIdsArray=nil,TotalAmountsArray=nil,StatusArray=nil,HoldIdsArray=nil,TimesArray=nil,CustomersArray=nil,EmployeesArray=nil;
    
    //Product Printer View
    NSArray *ProductPrinterPopUpArray = ProductPrinterPopUp.subviews;
    for (int i = 0; i<[ProductPrinterPopUpArray count]; i++) {
        UIView *vi =[ProductPrinterPopUpArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *ProductPrinterViewArray = ProductPrinterView.subviews;
    for (int i = 0; i<[ProductPrinterViewArray count]; i++) {
        UIView *vi =[ProductPrinterViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [ProductPrinterView removeFromSuperview],[ProductPrinterPopUp removeFromSuperview];
    ProductPrinterPopUp=nil;
    ProductPrinterView=nil;
    ProductPrintertable=nil;
    PrinterBtn=nil,TimeBtn=nil,SavePrintBtn=nil,CancelPrintBtn=nil;
    ProductTextView=nil;
    PrintTextlbl=nil;
    [DepPrinterDataArray removeAllObjects],[DepTimesArray removeAllObjects],[QtyitemsArry removeAllObjects],[ProductNamesArray removeAllObjects];
    DepPrinterDataArray=nil,DepTimesArray=nil,QtyitemsArry=nil,ProductNamesArray=nil;
    
    PrinterNamesArray=nil,MinitsArray=nil;
    
    //Printer View
    NSArray *printerPopupArray = printerPopup.subviews;
    for (int i = 0; i<[printerPopupArray count]; i++) {
        UIView *vi =[printerPopupArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [printerPopup removeFromSuperview];
    printerPopup=nil;
    PrinterNamesTable=nil,MinitsTable=nil;
    MinitsPopup=nil;
    
   
    EditPrinter=nil,DeleteinvoiceData=nil;
    //Employee Store Ids View
    StoresPopupView=nil,StoresView=nil;
    SelectStoreBtn=nil,ProceedStoreBtn=nil;
    
    StoresListTable=nil;
    [StoresArray removeAllObjects];
    StoresArray=nil;
    SelectStorelbl=nil;
    
    StoreID=nil;
    DeleteInvoiceAlert=nil;
   
    
    
    cellButton=nil;
    //Product scan view
    ProductscanBackView=nil,ProductScanView=nil;
    ScanTextlbl=nil;
    ProductScanField=nil;
    
    SaveBarCodeBtn=nil,CancelBarCodeBtn=nil,ScanItemBtn=nil;

    PrinterHoldID=nil;
    
    PrintLastInvcBtn=nil,RecallBtn=nil;
    
    
    //Search Data View
    NSArray *RecallViewpopupArray = RecallViewpopup.subviews;
    for (int i = 0; i<[RecallViewpopupArray count]; i++) {
        UIView *vi =[RecallViewpopupArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [RecallViewpopup removeFromSuperview];
    RecallViewpopup=nil;
    
    RecallListTable=nil;
    [RsonsArray removeAllObjects],[paymentTypesArray removeAllObjects];
    RsonsArray=nil,paymentTypesArray=nil;
    
    
    sationLbl=nil,Timelbl=nil,EmpIdlbl=nil;
    logoBtn=nil;
    
     SplitInvoiceBtn=nil;
    
    //Split Invoice View
    NSArray *SplitInvoicepopUpArray = SplitInvoicepopUp.subviews;
    for (int i = 0; i<[SplitInvoicepopUpArray count]; i++) {
        UIView *vi =[SplitInvoicepopUpArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *SplitInvoiceViewArray = SplitInvoiceView.subviews;
    for (int i = 0; i<[SplitInvoiceViewArray count]; i++) {
        UIView *vi =[SplitInvoiceViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [SplitInvoiceView removeFromSuperview];
    [SplitInvoicepopUp removeFromSuperview];
    
    SplitInvoicepopUp=nil,SplitInvoiceView=nil;
    SplitInvoiceLabel=nil;
    SplitInvoiceSaveBtn=nil;
    SplitInvoiceTextField=nil;
    [SplitNamesArray removeAllObjects],[SplitQytsArray removeAllObjects],[SplitPricesArray removeAllObjects];
    SplitNamesArray=nil,SplitQytsArray=nil,SplitPricesArray=nil;
    
    SplittablePopUpView=nil;
    SplittableBackView=nil;
    
    SplitDataTable=nil;
    
 
    
    //Divya coding
    
    //checknum Variables
    checkNumTxt=nil;
    
    checkNumLbl=nil;
    
    checkPopUp=nil,  checkPopUpPay=nil;
    
    checkNumBtn=nil;
    
    payment_type =nil,  split_amount=nil,  check_no=nil,  account_no=nil,  invoice_id=nil;
    
   
    SplitInvoiceID=nil;
    
    
    SplitInvoiceTable=nil;
    [SplitpaymentsArray removeAllObjects],[splitAmoutsArray removeAllObjects];
    SplitpaymentsArray=nil,splitAmoutsArray=nil;
    PrintSplitInvoiceID=nil,TotalPaymetType=nil;
    InvoiceCheckNo=nil;
    
    RecallInvoiceID=nil;
    
    InVoiceCustomer=nil;
    
    
    EmployeeID=nil;
    
    PrinttextView=nil;
    
     Printimage=nil;
   // [webView1 loadRequest:nil];
    //[webView1 removeFromSuperview];
   //  webView1=nil;
    
    [searchPrinterArray removeAllObjects];
    SearchPrinterStr=nil,searchPrinterArray=nil;
   
homeSearchCell=nil,recallInvoiceCell=nil,fetchonHoldCell=nil,splitInvoiceCell=nil,homeCustomerCell=nil,homeProductListCell=nil;
    NSArray *modifierPopupViewArray = modifierPopupView.subviews;
    for (int i = 0; i<[modifierPopupViewArray count]; i++) {
        UIView *vi =[modifierPopupViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *modifieViewArray = modifieView.subviews;
    for (int i = 0; i<[modifieViewArray count]; i++) {
        UIView *vi =[modifieViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [modifieView removeFromSuperview];
    [modifierPopupView removeFromSuperview];
    modifierPopupView=nil,modifieView=nil;
    okmodifier_Button=nil,cancelmodifier_Button=nil,modifierItem_Button=nil;
    [modifierItemsArray removeAllObjects],[selectedModifieritemsArray removeAllObjects];
    modifierItemsArray=nil,selectedModifieritemsArray=nil;
    [self.view removeFromSuperview];
    self.view=nil;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
      NSArray *viewS = [self.navigationController viewControllers];
     [self.navigationController popToViewController:[viewS objectAtIndex:1] animated:YES];
    [self releaseViews];
    
}

@end
